<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP, NoImplicitPrelude, NondecreasingIndentation,
             RecordWildCards, ScopedTypeVariables #-}</span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# OPTIONS_GHC -Wno-name-shadowing #-}</span><span>
</span><span id="line-5"></span><span>
</span><span id="line-6"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.IO.Encoding.CodePage.API</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-7"></span><span>    </span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#mkCodePageEncoding"><span class="hs-identifier">mkCodePageEncoding</span></a></span><span>
</span><span id="line-8"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Required for WORDS_BIGENDIAN</span><span class="hs-cpp">
#include &lt;ghcautoconf.h&gt;
</span><span>
</span><span id="line-13"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.html"><span class="hs-identifier">Foreign.C</span></a></span><span>
</span><span id="line-14"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Ptr.html"><span class="hs-identifier">Foreign.Ptr</span></a></span><span>
</span><span id="line-15"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Marshal.html"><span class="hs-identifier">Foreign.Marshal</span></a></span><span>
</span><span id="line-16"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.Storable.html"><span class="hs-identifier">Foreign.Storable</span></a></span><span>
</span><span id="line-17"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Bits.html"><span class="hs-identifier">Data.Bits</span></a></span><span>
</span><span id="line-18"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Either.html"><span class="hs-identifier">Data.Either</span></a></span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Word.html"><span class="hs-identifier">Data.Word</span></a></span><span>
</span><span id="line-20"></span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.List.html"><span class="hs-identifier">GHC.List</span></a></span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html"><span class="hs-identifier">GHC.IO.Buffer</span></a></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Failure.html"><span class="hs-identifier">GHC.IO.Encoding.Failure</span></a></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html"><span class="hs-identifier">GHC.IO.Encoding.Types</span></a></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.UTF16.html"><span class="hs-identifier">GHC.IO.Encoding.UTF16</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Show.html"><span class="hs-identifier">GHC.Show</span></a></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Windows.html"><span class="hs-identifier">GHC.Windows</span></a></span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Windows.html#LPCSTR"><span class="hs-identifier">LPCSTR</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.ForeignPtr.html"><span class="hs-identifier">GHC.ForeignPtr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.ForeignPtr.html#castForeignPtr"><span class="hs-identifier">castForeignPtr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-32"></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Posix.Internals.html"><span class="hs-identifier">System.Posix.Internals</span></a></span><span>
</span><span id="line-34"></span><span>
</span><span id="line-35"></span><span>
</span><span id="line-36"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#c_DEBUG_DUMP"><span class="hs-identifier hs-type">c_DEBUG_DUMP</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-37"></span><span id="c_DEBUG_DUMP"><span class="annot"><span class="annottext">c_DEBUG_DUMP :: Bool
</span><a href="GHC.IO.Encoding.CodePage.API.html#c_DEBUG_DUMP"><span class="hs-identifier hs-var hs-var">c_DEBUG_DUMP</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-38"></span><span>
</span><span id="line-39"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-type">debugIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-40"></span><span id="debugIO"><span class="annot"><span class="annottext">debugIO :: String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var hs-var">debugIO</span></a></span></span><span> </span><span id="local-6989586621679547091"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679547091"><span class="hs-identifier hs-var">s</span></a></span></span><span>
</span><span id="line-41"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.IO.Encoding.CodePage.API.html#c_DEBUG_DUMP"><span class="hs-identifier hs-var">c_DEBUG_DUMP</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="System.Posix.Internals.html#puts"><span class="hs-identifier hs-var">puts</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679547091"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-42"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">

#include &quot;windows_cconv.h&quot;
</span><span>
</span><span id="line-46"></span><span class="hs-keyword">type</span><span> </span><span id="LPCSTR"><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#LPCSTR"><span class="hs-identifier hs-var">LPCSTR</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>
</span><span id="line-47"></span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#mAX_DEFAULTCHAR"><span class="hs-identifier hs-type">mAX_DEFAULTCHAR</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-50"></span><span id="mAX_DEFAULTCHAR"><span class="annot"><span class="annottext">mAX_DEFAULTCHAR :: Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#mAX_DEFAULTCHAR"><span class="hs-identifier hs-var hs-var">mAX_DEFAULTCHAR</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span>
</span><span id="line-51"></span><span>
</span><span id="line-52"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#mAX_LEADBYTES"><span class="hs-identifier hs-type">mAX_LEADBYTES</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-53"></span><span id="mAX_LEADBYTES"><span class="annot"><span class="annottext">mAX_LEADBYTES :: Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#mAX_LEADBYTES"><span class="hs-identifier hs-var hs-var">mAX_LEADBYTES</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">12</span></span><span>
</span><span id="line-54"></span><span>
</span><span id="line-55"></span><span class="hs-comment">-- Don't really care about the contents of this, but we have to make sure the size is right</span><span>
</span><span id="line-56"></span><span class="hs-keyword">data</span><span> </span><span id="CPINFO"><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#CPINFO"><span class="hs-identifier hs-var">CPINFO</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="CPINFO"><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#CPINFO"><span class="hs-identifier hs-var">CPINFO</span></a></span></span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-57"></span><span>    </span><span id="maxCharSize"><span class="annot"><span class="annottext">CPINFO -&gt; Word32
</span><a href="GHC.IO.Encoding.CodePage.API.html#maxCharSize"><span class="hs-identifier hs-var hs-var">maxCharSize</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#UINT"><span class="hs-identifier hs-type">UINT</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-58"></span><span>    </span><span id="defaultChar"><span class="annot"><span class="annottext">CPINFO -&gt; [Word8]
</span><a href="GHC.IO.Encoding.CodePage.API.html#defaultChar"><span class="hs-identifier hs-var hs-var">defaultChar</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Windows.html#BYTE"><span class="hs-identifier hs-type">BYTE</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-comment">-- ^ Always of length mAX_DEFAULTCHAR</span><span>
</span><span id="line-59"></span><span>    </span><span id="leadByte"><span class="annot"><span class="annottext">CPINFO -&gt; [Word8]
</span><a href="GHC.IO.Encoding.CodePage.API.html#leadByte"><span class="hs-identifier hs-var hs-var">leadByte</span></a></span></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Windows.html#BYTE"><span class="hs-identifier hs-type">BYTE</span></a></span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- ^ Always of length mAX_LEADBYTES</span><span>
</span><span id="line-60"></span><span>  </span><span class="hs-special">}</span><span>
</span><span id="line-61"></span><span>
</span><span id="line-62"></span><span class="hs-comment">-- | @since 4.7.0.0</span><span>
</span><span id="line-63"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679547071"><span id="local-6989586621679547073"><span id="local-6989586621679547075"><span id="local-6989586621679547077"><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#CPINFO"><span class="hs-identifier hs-type">CPINFO</span></a></span></span></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-64"></span><span>    </span><span id="local-6989586621679547057"><span class="annot"><span class="annottext">sizeOf :: CPINFO -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var hs-var hs-var hs-var">sizeOf</span></a></span></span><span>    </span><span class="annot"><span class="annottext">CPINFO
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word32
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#UINT"><span class="hs-identifier hs-type">UINT</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#mAX_DEFAULTCHAR"><span class="hs-identifier hs-var">mAX_DEFAULTCHAR</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#mAX_LEADBYTES"><span class="hs-identifier hs-var">mAX_LEADBYTES</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Word8 -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word8
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#BYTE"><span class="hs-identifier hs-type">BYTE</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-65"></span><span>    </span><span id="local-6989586621679547048"><span class="annot"><span class="annottext">alignment :: CPINFO -&gt; Int
</span><a href="Foreign.Storable.html#alignment"><span class="hs-identifier hs-var hs-var hs-var hs-var">alignment</span></a></span></span><span> </span><span class="annot"><span class="annottext">CPINFO
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CInt -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="Foreign.Storable.html#alignment"><span class="hs-identifier hs-var">alignment</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CInt
forall a. HasCallStack =&gt; a
</span><a href="GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-66"></span><span>    </span><span id="local-6989586621679547033"><span class="annot"><span class="annottext">peek :: Ptr CPINFO -&gt; IO CPINFO
</span><a href="Foreign.Storable.html#peek"><span class="hs-identifier hs-var hs-var hs-var hs-var">peek</span></a></span></span><span> </span><span id="local-6989586621679547031"><span class="annot"><span class="annottext">Ptr CPINFO
</span><a href="#local-6989586621679547031"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-67"></span><span>      </span><span id="local-6989586621679547030"><span class="annot"><span class="annottext">Ptr Word32
</span><a href="#local-6989586621679547030"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word32 -&gt; IO (Ptr Word32)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Ptr Word32 -&gt; IO (Ptr Word32)) -&gt; Ptr Word32 -&gt; IO (Ptr Word32)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CPINFO -&gt; Ptr Word32
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CPINFO
</span><a href="#local-6989586621679547031"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-68"></span><span>      </span><span id="local-6989586621679547028"><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679547028"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word32 -&gt; IO Word32
forall a. Storable a =&gt; Ptr a -&gt; IO a
</span><a href="Foreign.Storable.html#peek"><span class="hs-identifier hs-var">peek</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word32
</span><a href="#local-6989586621679547030"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-69"></span><span>      </span><span id="local-6989586621679547027"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679547027"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; IO (Ptr Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word32 -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">(Ptr Word32 -&gt; Ptr Word8) -&gt; Ptr Word32 -&gt; Ptr Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word32 -&gt; Int -&gt; Ptr Word32
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; Ptr a
</span><a href="Foreign.Marshal.Array.html#advancePtr"><span class="hs-identifier hs-var">advancePtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word32
</span><a href="#local-6989586621679547030"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span>
</span><span id="line-70"></span><span>      </span><span id="local-6989586621679547025"><span class="annot"><span class="annottext">[Word8]
</span><a href="#local-6989586621679547025"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Ptr Word8 -&gt; IO [Word8]
forall a. Storable a =&gt; Int -&gt; Ptr a -&gt; IO [a]
</span><a href="Foreign.Marshal.Array.html#peekArray"><span class="hs-identifier hs-var">peekArray</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#mAX_DEFAULTCHAR"><span class="hs-identifier hs-var">mAX_DEFAULTCHAR</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679547027"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-71"></span><span>      </span><span id="local-6989586621679547023"><span class="annot"><span class="annottext">[Word8]
</span><a href="#local-6989586621679547023"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Ptr Word8 -&gt; IO [Word8]
forall a. Storable a =&gt; Int -&gt; Ptr a -&gt; IO [a]
</span><a href="Foreign.Marshal.Array.html#peekArray"><span class="hs-identifier hs-var">peekArray</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#mAX_LEADBYTES"><span class="hs-identifier hs-var">mAX_LEADBYTES</span></a></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; Ptr a
</span><a href="Foreign.Marshal.Array.html#advancePtr"><span class="hs-identifier hs-var">advancePtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679547027"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#mAX_DEFAULTCHAR"><span class="hs-identifier hs-var">mAX_DEFAULTCHAR</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-72"></span><span>      </span><span class="annot"><span class="annottext">CPINFO -&gt; IO CPINFO
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(CPINFO -&gt; IO CPINFO) -&gt; CPINFO -&gt; IO CPINFO
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; [Word8] -&gt; [Word8] -&gt; CPINFO
</span><a href="GHC.IO.Encoding.CodePage.API.html#CPINFO"><span class="hs-identifier hs-var">CPINFO</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679547028"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">[Word8]
</span><a href="#local-6989586621679547025"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="annot"><span class="annottext">[Word8]
</span><a href="#local-6989586621679547023"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-73"></span><span>    </span><span id="local-6989586621679547011"><span class="annot"><span class="annottext">poke :: Ptr CPINFO -&gt; CPINFO -&gt; IO ()
</span><a href="Foreign.Storable.html#poke"><span class="hs-identifier hs-var hs-var hs-var hs-var">poke</span></a></span></span><span> </span><span id="local-6989586621679547009"><span class="annot"><span class="annottext">Ptr CPINFO
</span><a href="#local-6989586621679547009"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679547008"><span class="annot"><span class="annottext">CPINFO
</span><a href="#local-6989586621679547008"><span class="hs-identifier hs-var">val</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-74"></span><span>      </span><span id="local-6989586621679547007"><span class="annot"><span class="annottext">Ptr Word32
</span><a href="#local-6989586621679547007"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word32 -&gt; IO (Ptr Word32)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Ptr Word32 -&gt; IO (Ptr Word32)) -&gt; Ptr Word32 -&gt; IO (Ptr Word32)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CPINFO -&gt; Ptr Word32
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CPINFO
</span><a href="#local-6989586621679547009"><span class="hs-identifier hs-var">ptr</span></a></span><span>
</span><span id="line-75"></span><span>      </span><span class="annot"><span class="annottext">Ptr Word32 -&gt; Word32 -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#poke"><span class="hs-identifier hs-var">poke</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word32
</span><a href="#local-6989586621679547007"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CPINFO -&gt; Word32
</span><a href="GHC.IO.Encoding.CodePage.API.html#maxCharSize"><span class="hs-identifier hs-var hs-var">maxCharSize</span></a></span><span> </span><span class="annot"><span class="annottext">CPINFO
</span><a href="#local-6989586621679547008"><span class="hs-identifier hs-var">val</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-76"></span><span>      </span><span id="local-6989586621679547006"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679547006"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; IO (Ptr Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word32 -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">(Ptr Word32 -&gt; Ptr Word8) -&gt; Ptr Word32 -&gt; Ptr Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word32 -&gt; Int -&gt; Ptr Word32
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; Ptr a
</span><a href="Foreign.Marshal.Array.html#advancePtr"><span class="hs-identifier hs-var">advancePtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word32
</span><a href="#local-6989586621679547007"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span>
</span><span id="line-77"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; Ptr Word8 -&gt; [Word8] -&gt; IO ()
forall a. Storable a =&gt; String -&gt; Int -&gt; Ptr a -&gt; [a] -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#pokeArray%27"><span class="hs-identifier hs-var">pokeArray'</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;CPINFO.defaultChar&quot;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#mAX_DEFAULTCHAR"><span class="hs-identifier hs-var">mAX_DEFAULTCHAR</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679547006"><span class="hs-identifier hs-var">ptr</span></a></span><span>                              </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CPINFO -&gt; [Word8]
</span><a href="GHC.IO.Encoding.CodePage.API.html#defaultChar"><span class="hs-identifier hs-var hs-var">defaultChar</span></a></span><span> </span><span class="annot"><span class="annottext">CPINFO
</span><a href="#local-6989586621679547008"><span class="hs-identifier hs-var">val</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-78"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; Ptr Word8 -&gt; [Word8] -&gt; IO ()
forall a. Storable a =&gt; String -&gt; Int -&gt; Ptr a -&gt; [a] -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#pokeArray%27"><span class="hs-identifier hs-var">pokeArray'</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;CPINFO.leadByte&quot;</span></span><span>    </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#mAX_LEADBYTES"><span class="hs-identifier hs-var">mAX_LEADBYTES</span></a></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; Ptr a
</span><a href="Foreign.Marshal.Array.html#advancePtr"><span class="hs-identifier hs-var">advancePtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679547006"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#mAX_DEFAULTCHAR"><span class="hs-identifier hs-var">mAX_DEFAULTCHAR</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CPINFO -&gt; [Word8]
</span><a href="GHC.IO.Encoding.CodePage.API.html#leadByte"><span class="hs-identifier hs-var hs-var">leadByte</span></a></span><span> </span><span class="annot"><span class="annottext">CPINFO
</span><a href="#local-6989586621679547008"><span class="hs-identifier hs-var">val</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-79"></span><span>
</span><span id="line-80"></span><span id="local-6989586621679547273"><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#pokeArray%27"><span class="hs-identifier hs-type">pokeArray'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547273"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547273"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679547273"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-81"></span><span id="pokeArray%27"><span class="annot"><span class="annottext">pokeArray' :: forall a. Storable a =&gt; String -&gt; Int -&gt; Ptr a -&gt; [a] -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#pokeArray%27"><span class="hs-identifier hs-var hs-var">pokeArray'</span></a></span></span><span> </span><span id="local-6989586621679546998"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679546998"><span class="hs-identifier hs-var">msg</span></a></span></span><span> </span><span id="local-6989586621679546997"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546997"><span class="hs-identifier hs-var">sz</span></a></span></span><span> </span><span id="local-6989586621679546996"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679546996"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679546995"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679546995"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; Int
forall a. [a] -&gt; Int
</span><a href="GHC.List.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679546995"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546997"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; [a] -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; [a] -&gt; IO ()
</span><a href="Foreign.Marshal.Array.html#pokeArray"><span class="hs-identifier hs-var">pokeArray</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679546996"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679546995"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-82"></span><span>                         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
forall a. String -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679546998"><span class="hs-identifier hs-var">msg</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;: expected &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546997"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; elements in list but got &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[a] -&gt; Int
forall a. [a] -&gt; Int
</span><a href="GHC.List.html#length"><span class="hs-identifier hs-var">length</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679546995"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-83"></span><span>
</span><span id="line-84"></span><span>
</span><span id="line-85"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h GetCPInfo&quot;</span><span>
</span><span id="line-86"></span><span>    </span><span id="c_GetCPInfo"><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#c_GetCPInfo"><span class="hs-identifier hs-var">c_GetCPInfo</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#UINT"><span class="hs-identifier hs-type">UINT</span></a></span><span>       </span><span class="hs-comment">-- ^ CodePage</span><span>
</span><span id="line-87"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#CPINFO"><span class="hs-identifier hs-type">CPINFO</span></a></span><span> </span><span class="hs-comment">-- ^ lpCPInfo</span><span>
</span><span id="line-88"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Windows.html#BOOL"><span class="hs-identifier hs-type">BOOL</span></a></span><span>
</span><span id="line-89"></span><span>
</span><span id="line-90"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h MultiByteToWideChar&quot;</span><span>
</span><span id="line-91"></span><span>    </span><span id="c_MultiByteToWideChar"><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#c_MultiByteToWideChar"><span class="hs-identifier hs-var">c_MultiByteToWideChar</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#UINT"><span class="hs-identifier hs-type">UINT</span></a></span><span>   </span><span class="hs-comment">-- ^ CodePage</span><span>
</span><span id="line-92"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Windows.html#DWORD"><span class="hs-identifier hs-type">DWORD</span></a></span><span>  </span><span class="hs-comment">-- ^ dwFlags</span><span>
</span><span id="line-93"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#LPCSTR"><span class="hs-identifier hs-type">LPCSTR</span></a></span><span> </span><span class="hs-comment">-- ^ lpMultiByteStr</span><span>
</span><span id="line-94"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>   </span><span class="hs-comment">-- ^ cbMultiByte</span><span>
</span><span id="line-95"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Windows.html#LPWSTR"><span class="hs-identifier hs-type">LPWSTR</span></a></span><span> </span><span class="hs-comment">-- ^ lpWideCharStr</span><span>
</span><span id="line-96"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>   </span><span class="hs-comment">-- ^ cchWideChar</span><span>
</span><span id="line-97"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>
</span><span id="line-98"></span><span>
</span><span id="line-99"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h WideCharToMultiByte&quot;</span><span>
</span><span id="line-100"></span><span>    </span><span id="c_WideCharToMultiByte"><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#c_WideCharToMultiByte"><span class="hs-identifier hs-var">c_WideCharToMultiByte</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#UINT"><span class="hs-identifier hs-type">UINT</span></a></span><span>   </span><span class="hs-comment">-- ^ CodePage</span><span>
</span><span id="line-101"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Windows.html#DWORD"><span class="hs-identifier hs-type">DWORD</span></a></span><span>  </span><span class="hs-comment">-- ^ dwFlags</span><span>
</span><span id="line-102"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Windows.html#LPWSTR"><span class="hs-identifier hs-type">LPWSTR</span></a></span><span> </span><span class="hs-comment">-- ^ lpWideCharStr</span><span>
</span><span id="line-103"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>   </span><span class="hs-comment">-- ^ cchWideChar</span><span>
</span><span id="line-104"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#LPCSTR"><span class="hs-identifier hs-type">LPCSTR</span></a></span><span> </span><span class="hs-comment">-- ^ lpMultiByteStr</span><span>
</span><span id="line-105"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>   </span><span class="hs-comment">-- ^ cbMultiByte</span><span>
</span><span id="line-106"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#LPCSTR"><span class="hs-identifier hs-type">LPCSTR</span></a></span><span> </span><span class="hs-comment">-- ^ lpDefaultChar</span><span>
</span><span id="line-107"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Windows.html#LPBOOL"><span class="hs-identifier hs-type">LPBOOL</span></a></span><span> </span><span class="hs-comment">-- ^ lpUsedDefaultChar</span><span>
</span><span id="line-108"></span><span>                          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CInt"><span class="hs-identifier hs-type">CInt</span></a></span><span>
</span><span id="line-109"></span><span>
</span><span id="line-110"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h IsDBCSLeadByteEx&quot;</span><span>
</span><span id="line-111"></span><span>    </span><span id="c_IsDBCSLeadByteEx"><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#c_IsDBCSLeadByteEx"><span class="hs-identifier hs-var">c_IsDBCSLeadByteEx</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Windows.html#UINT"><span class="hs-identifier hs-type">UINT</span></a></span><span>    </span><span class="hs-comment">-- ^ CodePage</span><span>
</span><span id="line-112"></span><span>                       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Windows.html#BYTE"><span class="hs-identifier hs-type">BYTE</span></a></span><span>    </span><span class="hs-comment">-- ^ TestChar</span><span>
</span><span id="line-113"></span><span>                       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Windows.html#BOOL"><span class="hs-identifier hs-type">BOOL</span></a></span><span>
</span><span id="line-114"></span><span>
</span><span id="line-115"></span><span>
</span><span id="line-116"></span><span class="hs-comment">-- | Returns a slow but correct implementation of TextEncoding using the Win32 API.</span><span>
</span><span id="line-117"></span><span class="hs-comment">--</span><span>
</span><span id="line-118"></span><span class="hs-comment">-- This is useful for supporting DBCS text encoding on the console without having to statically link</span><span>
</span><span id="line-119"></span><span class="hs-comment">-- in huge code tables into all of our executables, or just as a fallback mechanism if a new code page</span><span>
</span><span id="line-120"></span><span class="hs-comment">-- is introduced that we don't know how to deal with ourselves yet.</span><span>
</span><span id="line-121"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#mkCodePageEncoding"><span class="hs-identifier hs-type">mkCodePageEncoding</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Failure.html#CodingFailureMode"><span class="hs-identifier hs-type">CodingFailureMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Word.html#Word32"><span class="hs-identifier hs-type">Word32</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#TextEncoding"><span class="hs-identifier hs-type">TextEncoding</span></a></span><span>
</span><span id="line-122"></span><span id="mkCodePageEncoding"><span class="annot"><span class="annottext">mkCodePageEncoding :: CodingFailureMode -&gt; Word32 -&gt; TextEncoding
</span><a href="GHC.IO.Encoding.CodePage.API.html#mkCodePageEncoding"><span class="hs-identifier hs-var hs-var">mkCodePageEncoding</span></a></span></span><span> </span><span id="local-6989586621679546982"><span class="annot"><span class="annottext">CodingFailureMode
</span><a href="#local-6989586621679546982"><span class="hs-identifier hs-var">cfm</span></a></span></span><span> </span><span id="local-6989586621679546981"><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546981"><span class="hs-identifier hs-var">cp</span></a></span></span><span>
</span><span id="line-123"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TextEncoding :: forall dstate estate.
String
-&gt; IO (TextDecoder dstate)
-&gt; IO (TextEncoder estate)
-&gt; TextEncoding
</span><a href="GHC.IO.Encoding.Types.html#TextEncoding"><span class="hs-identifier hs-type">TextEncoding</span></a></span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-124"></span><span>        </span><span class="annot"><span class="annottext">textEncodingName :: String
</span><a href="GHC.IO.Encoding.Types.html#textEncodingName"><span class="hs-identifier hs-var">textEncodingName</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;CP&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546981"><span class="hs-identifier hs-var">cp</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-125"></span><span>        </span><span class="annot"><span class="annottext">mkTextDecoder :: IO (TextDecoder ())
</span><a href="GHC.IO.Encoding.Types.html#mkTextDecoder"><span class="hs-identifier hs-var">mkTextDecoder</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Word8, Buffer Char))
-&gt; (Word32 -&gt; Int -&gt; CodeBuffer Word8 Char)
-&gt; Word32
-&gt; IO (TextDecoder ())
forall from to.
(Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to))
-&gt; (Word32 -&gt; Int -&gt; CodeBuffer from to)
-&gt; Word32
-&gt; IO (BufferCodec from to ())
</span><a href="GHC.IO.Encoding.CodePage.API.html#newCP"><span class="hs-identifier hs-var">newCP</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingFailureMode
-&gt; Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Word8, Buffer Char)
</span><a href="GHC.IO.Encoding.Failure.html#recoverDecode"><span class="hs-identifier hs-var">recoverDecode</span></a></span><span> </span><span class="annot"><span class="annottext">CodingFailureMode
</span><a href="#local-6989586621679546982"><span class="hs-identifier hs-var">cfm</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; Int -&gt; CodeBuffer Word8 Char
</span><a href="GHC.IO.Encoding.CodePage.API.html#cpDecode"><span class="hs-identifier hs-var">cpDecode</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546981"><span class="hs-identifier hs-var">cp</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-126"></span><span>        </span><span class="annot"><span class="annottext">mkTextEncoder :: IO (TextEncoder ())
</span><a href="GHC.IO.Encoding.Types.html#mkTextEncoder"><span class="hs-identifier hs-var">mkTextEncoder</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Buffer Char -&gt; Buffer Word8 -&gt; IO (Buffer Char, Buffer Word8))
-&gt; (Word32 -&gt; Int -&gt; CodeBuffer Char Word8)
-&gt; Word32
-&gt; IO (TextEncoder ())
forall from to.
(Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to))
-&gt; (Word32 -&gt; Int -&gt; CodeBuffer from to)
-&gt; Word32
-&gt; IO (BufferCodec from to ())
</span><a href="GHC.IO.Encoding.CodePage.API.html#newCP"><span class="hs-identifier hs-var">newCP</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingFailureMode
-&gt; Buffer Char -&gt; Buffer Word8 -&gt; IO (Buffer Char, Buffer Word8)
</span><a href="GHC.IO.Encoding.Failure.html#recoverEncode"><span class="hs-identifier hs-var">recoverEncode</span></a></span><span> </span><span class="annot"><span class="annottext">CodingFailureMode
</span><a href="#local-6989586621679546982"><span class="hs-identifier hs-var">cfm</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; Int -&gt; CodeBuffer Char Word8
</span><a href="GHC.IO.Encoding.CodePage.API.html#cpEncode"><span class="hs-identifier hs-var">cpEncode</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546981"><span class="hs-identifier hs-var">cp</span></a></span><span>
</span><span id="line-127"></span><span>      </span><span class="hs-special">}</span><span>
</span><span id="line-128"></span><span>
</span><span id="line-129"></span><span id="local-6989586621679547255"><span id="local-6989586621679547256"><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#newCP"><span class="hs-identifier hs-type">newCP</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547256"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547255"><span class="hs-identifier hs-type">to</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547256"><span class="hs-identifier hs-type">from</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547255"><span class="hs-identifier hs-type">to</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-130"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Word.html#Word32"><span class="hs-identifier hs-type">Word32</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#CodeBuffer"><span class="hs-identifier hs-type">CodeBuffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547256"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547255"><span class="hs-identifier hs-type">to</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-131"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Word.html#Word32"><span class="hs-identifier hs-type">Word32</span></a></span><span>
</span><span id="line-132"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Encoding.Types.html#BufferCodec"><span class="hs-identifier hs-type">BufferCodec</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547256"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547255"><span class="hs-identifier hs-type">to</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-133"></span><span id="newCP"><span class="annot"><span class="annottext">newCP :: forall from to.
(Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to))
-&gt; (Word32 -&gt; Int -&gt; CodeBuffer from to)
-&gt; Word32
-&gt; IO (BufferCodec from to ())
</span><a href="GHC.IO.Encoding.CodePage.API.html#newCP"><span class="hs-identifier hs-var hs-var">newCP</span></a></span></span><span> </span><span id="local-6989586621679546951"><span class="annot"><span class="annottext">Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
</span><a href="#local-6989586621679546951"><span class="hs-identifier hs-var">rec</span></a></span></span><span> </span><span id="local-6989586621679546950"><span class="annot"><span class="annottext">Word32 -&gt; Int -&gt; CodeBuffer from to
</span><a href="#local-6989586621679546950"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span id="local-6989586621679546949"><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546949"><span class="hs-identifier hs-var">cp</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-134"></span><span>  </span><span class="hs-comment">-- Fail early if the code page doesn't exist, to match the behaviour of the IConv TextEncoding</span><span>
</span><span id="line-135"></span><span>  </span><span id="local-6989586621679546948"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546948"><span class="hs-identifier hs-var">max_char_size</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Ptr CPINFO -&gt; IO Int) -&gt; IO Int
forall a b. Storable a =&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-identifier hs-var">alloca</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr CPINFO -&gt; IO Int) -&gt; IO Int)
-&gt; (Ptr CPINFO -&gt; IO Int) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679546946"><span class="annot"><span class="annottext">Ptr CPINFO
</span><a href="#local-6989586621679546946"><span class="hs-identifier hs-var">cpinfo_ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-136"></span><span>    </span><span id="local-6989586621679546945"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546945"><span class="hs-identifier hs-var">success</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; Ptr CPINFO -&gt; IO Bool
</span><a href="GHC.IO.Encoding.CodePage.API.html#c_GetCPInfo"><span class="hs-identifier hs-var">c_GetCPInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546949"><span class="hs-identifier hs-var">cp</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CPINFO
</span><a href="#local-6989586621679546946"><span class="hs-identifier hs-var">cpinfo_ptr</span></a></span><span>
</span><span id="line-137"></span><span>    </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546945"><span class="hs-identifier hs-var">success</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
forall a. String -&gt; IO a
</span><a href="GHC.Windows.html#throwGetLastError"><span class="hs-identifier hs-var">throwGetLastError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;GetCPInfo &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546949"><span class="hs-identifier hs-var">cp</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-138"></span><span>    </span><span class="annot"><span class="annottext">(CPINFO -&gt; Int) -&gt; IO CPINFO -&gt; IO Int
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word32 -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">(Word32 -&gt; Int) -&gt; (CPINFO -&gt; Word32) -&gt; CPINFO -&gt; Int
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">CPINFO -&gt; Word32
</span><a href="GHC.IO.Encoding.CodePage.API.html#maxCharSize"><span class="hs-identifier hs-var hs-var">maxCharSize</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO CPINFO -&gt; IO Int) -&gt; IO CPINFO -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CPINFO -&gt; IO CPINFO
forall a. Storable a =&gt; Ptr a -&gt; IO a
</span><a href="Foreign.Storable.html#peek"><span class="hs-identifier hs-var">peek</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CPINFO
</span><a href="#local-6989586621679546946"><span class="hs-identifier hs-var">cpinfo_ptr</span></a></span><span>
</span><span id="line-139"></span><span>
</span><span id="line-140"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;GetCPInfo &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546949"><span class="hs-identifier hs-var">cp</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; = &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546948"><span class="hs-identifier hs-var">max_char_size</span></a></span><span>
</span><span id="line-141"></span><span>
</span><span id="line-142"></span><span>  </span><span class="annot"><span class="annottext">BufferCodec from to () -&gt; IO (BufferCodec from to ())
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(BufferCodec from to () -&gt; IO (BufferCodec from to ()))
-&gt; BufferCodec from to () -&gt; IO (BufferCodec from to ())
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">BufferCodec :: forall from to state.
CodeBuffer from to
-&gt; (Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to))
-&gt; IO ()
-&gt; IO state
-&gt; (state -&gt; IO ())
-&gt; BufferCodec from to state
</span><a href="GHC.IO.Encoding.Types.html#BufferCodec"><span class="hs-identifier hs-type">BufferCodec</span></a></span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-143"></span><span>    </span><span class="annot"><span class="annottext">encode :: CodeBuffer from to
</span><a href="GHC.IO.Encoding.Types.html#encode"><span class="hs-identifier hs-var">encode</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; Int -&gt; CodeBuffer from to
</span><a href="#local-6989586621679546950"><span class="hs-identifier hs-var">fn</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546949"><span class="hs-identifier hs-var">cp</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546948"><span class="hs-identifier hs-var">max_char_size</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-144"></span><span>    </span><span class="annot"><span class="annottext">recover :: Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
</span><a href="GHC.IO.Encoding.Types.html#recover"><span class="hs-identifier hs-var">recover</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
</span><a href="#local-6989586621679546951"><span class="hs-identifier hs-var">rec</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-145"></span><span>    </span><span class="annot"><span class="annottext">close :: IO ()
</span><a href="GHC.IO.Encoding.Types.html#close"><span class="hs-identifier hs-var">close</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-146"></span><span>    </span><span class="hs-comment">-- Windows doesn't supply a way to save/restore the state and doesn't need one</span><span>
</span><span id="line-147"></span><span>    </span><span class="hs-comment">-- since it's a dumb string-&gt;string API rather than a clever streaming one.</span><span>
</span><span id="line-148"></span><span>    </span><span class="annot"><span class="annottext">getState :: IO ()
</span><a href="GHC.IO.Encoding.Types.html#getState"><span class="hs-identifier hs-var">getState</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-149"></span><span>    </span><span class="annot"><span class="annottext">setState :: () -&gt; IO ()
</span><a href="GHC.IO.Encoding.Types.html#setState"><span class="hs-identifier hs-var">setState</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; () -&gt; IO ()
forall a b. a -&gt; b -&gt; a
</span><a href="GHC.Base.html#const"><span class="hs-identifier hs-var">const</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; () -&gt; IO ()) -&gt; IO () -&gt; () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-150"></span><span>  </span><span class="hs-special">}</span><span>
</span><span id="line-151"></span><span>
</span><span id="line-152"></span><span>
</span><span id="line-153"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_encode%27"><span class="hs-identifier hs-type">utf16_native_encode'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#EncodeBuffer"><span class="hs-identifier hs-type">EncodeBuffer</span></a></span><span>
</span><span id="line-154"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_decode%27"><span class="hs-identifier hs-type">utf16_native_decode'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#DecodeBuffer"><span class="hs-identifier hs-type">DecodeBuffer</span></a></span><span class="hs-cpp">
#if defined(WORDS_BIGENDIAN)
</span><span class="hs-identifier">utf16_native_encode'</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">utf16be_encode</span><span>
</span><span id="line-157"></span><span class="hs-identifier">utf16_native_decode'</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">utf16be_decode</span><span class="hs-cpp">
#else
</span><span id="utf16_native_encode%27"><span class="annot"><span class="annottext">utf16_native_encode' :: CodeBuffer Char Word8
</span><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_encode%27"><span class="hs-identifier hs-var hs-var">utf16_native_encode'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CodeBuffer Char Word8
</span><a href="GHC.IO.Encoding.UTF16.html#utf16le_encode"><span class="hs-identifier hs-var">utf16le_encode</span></a></span><span>
</span><span id="line-160"></span><span id="utf16_native_decode%27"><span class="annot"><span class="annottext">utf16_native_decode' :: CodeBuffer Word8 Char
</span><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_decode%27"><span class="hs-identifier hs-var hs-var">utf16_native_decode'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CodeBuffer Word8 Char
</span><a href="GHC.IO.Encoding.UTF16.html#utf16le_decode"><span class="hs-identifier hs-var">utf16le_decode</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-163"></span><span id="local-6989586621679547233"><span id="local-6989586621679547234"><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#saner"><span class="hs-identifier hs-type">saner</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#CodeBuffer"><span class="hs-identifier hs-type">CodeBuffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547234"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547233"><span class="hs-identifier hs-type">to</span></a></span><span>
</span><span id="line-164"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547234"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547233"><span class="hs-identifier hs-type">to</span></a></span><span>
</span><span id="line-165"></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Encoding.Types.html#CodingProgress"><span class="hs-identifier hs-type">CodingProgress</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547234"><span class="hs-identifier hs-type">from</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547233"><span class="hs-identifier hs-type">to</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-166"></span><span id="saner"><span class="annot"><span class="annottext">saner :: forall from to.
CodeBuffer from to
-&gt; Buffer from
-&gt; Buffer to
-&gt; IO (CodingProgress, Int, Buffer from, Buffer to)
</span><a href="GHC.IO.Encoding.CodePage.API.html#saner"><span class="hs-identifier hs-var hs-var">saner</span></a></span></span><span> </span><span id="local-6989586621679546922"><span class="annot"><span class="annottext">CodeBuffer from to
</span><a href="#local-6989586621679546922"><span class="hs-identifier hs-var">code</span></a></span></span><span> </span><span id="local-6989586621679546921"><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546921"><span class="hs-identifier hs-var">ibuf</span></a></span></span><span> </span><span id="local-6989586621679546920"><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546920"><span class="hs-identifier hs-var">obuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-167"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679546919"><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546919"><span class="hs-identifier hs-var">why</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546918"><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546918"><span class="hs-identifier hs-var">ibuf'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546917"><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546917"><span class="hs-identifier hs-var">obuf'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CodeBuffer from to
</span><a href="#local-6989586621679546922"><span class="hs-identifier hs-var">code</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546921"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546920"><span class="hs-identifier hs-var">obuf</span></a></span><span>
</span><span id="line-168"></span><span>  </span><span class="hs-comment">-- Weird but true: the UTF16 codes have a special case (see the &quot;done&quot; functions)</span><span>
</span><span id="line-169"></span><span>  </span><span class="hs-comment">-- whereby if they entirely consume the input instead of returning an input buffer</span><span>
</span><span id="line-170"></span><span>  </span><span class="hs-comment">-- that is empty because bufL has reached bufR, they return a buffer that is empty</span><span>
</span><span id="line-171"></span><span>  </span><span class="hs-comment">-- because bufL = bufR = 0.</span><span>
</span><span id="line-172"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-173"></span><span>  </span><span class="hs-comment">-- This is really very odd and confusing for our code that expects the difference</span><span>
</span><span id="line-174"></span><span>  </span><span class="hs-comment">-- between the old and new input buffer bufLs to indicate the number of elements</span><span>
</span><span id="line-175"></span><span>  </span><span class="hs-comment">-- that were consumed!</span><span>
</span><span id="line-176"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-177"></span><span>  </span><span class="hs-comment">-- We fix it by explicitly extracting an integer which is the # of things consumed, like so:</span><span>
</span><span id="line-178"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546918"><span class="hs-identifier hs-var">ibuf'</span></a></span><span>
</span><span id="line-179"></span><span>   </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">(CodingProgress, Int, Buffer from, Buffer to)
-&gt; IO (CodingProgress, Int, Buffer from, Buffer to)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#InputUnderflow"><span class="hs-identifier hs-var">InputUnderflow</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546921"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">,</span><span>       </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546918"><span class="hs-identifier hs-var">ibuf'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546917"><span class="hs-identifier hs-var">obuf'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-180"></span><span>   </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">(CodingProgress, Int, Buffer from, Buffer to)
-&gt; IO (CodingProgress, Int, Buffer from, Buffer to)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546919"><span class="hs-identifier hs-var">why</span></a></span><span class="hs-special">,</span><span>            </span><span class="annot"><span class="annottext">Buffer from -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546918"><span class="hs-identifier hs-var">ibuf'</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546921"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546918"><span class="hs-identifier hs-var">ibuf'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546917"><span class="hs-identifier hs-var">obuf'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-181"></span><span>
</span><span id="line-182"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#byteView"><span class="hs-identifier hs-type">byteView</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>
</span><span id="line-183"></span><span id="byteView"><span class="annot"><span class="annottext">byteView :: Buffer CWchar -&gt; Buffer Word8
</span><a href="GHC.IO.Encoding.CodePage.API.html#byteView"><span class="hs-identifier hs-var hs-var">byteView</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="hs-special">{</span><span id="local-6989586621679546905"><span id="local-6989586621679546906"><span id="local-6989586621679546907"><span id="local-6989586621679546908"><span id="local-6989586621679546909"><span id="local-6989586621679546910"><span class="annot"><span class="annottext">Int
Word64
RawBuffer CWchar
BufferState
bufState :: forall e. Buffer e -&gt; BufferState
bufSize :: forall e. Buffer e -&gt; Int
bufRaw :: forall e. Buffer e -&gt; RawBuffer e
bufR :: forall e. Buffer e -&gt; Int
bufOffset :: forall e. Buffer e -&gt; Word64
bufR :: Int
bufL :: Int
bufOffset :: Word64
bufSize :: Int
bufState :: BufferState
bufRaw :: RawBuffer CWchar
bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer :: forall e.
RawBuffer e
-&gt; BufferState -&gt; Int -&gt; Word64 -&gt; Int -&gt; Int -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufState :: BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var">bufState</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679546909"><span class="hs-identifier hs-var">bufState</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufRaw :: RawBuffer Word8
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RawBuffer CWchar -&gt; RawBuffer Word8
forall a b. ForeignPtr a -&gt; ForeignPtr b
</span><a href="GHC.ForeignPtr.html#castForeignPtr"><span class="hs-identifier hs-var">castForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer CWchar
</span><a href="#local-6989586621679546910"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546908"><span class="hs-identifier hs-var">bufSize</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufOffset :: Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679546907"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546906"><span class="hs-identifier hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546905"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-184"></span><span>
</span><span id="line-185"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#cwcharView"><span class="hs-identifier hs-type">cwcharView</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span>
</span><span id="line-186"></span><span id="cwcharView"><span class="annot"><span class="annottext">cwcharView :: Buffer Word8 -&gt; Buffer CWchar
</span><a href="GHC.IO.Encoding.CodePage.API.html#cwcharView"><span class="hs-identifier hs-var hs-var">cwcharView</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="hs-special">{</span><span id="local-6989586621679546893"><span id="local-6989586621679546894"><span id="local-6989586621679546895"><span id="local-6989586621679546896"><span id="local-6989586621679546897"><span id="local-6989586621679546898"><span class="annot"><span class="annottext">Int
Word64
RawBuffer Word8
BufferState
bufR :: Int
bufL :: Int
bufOffset :: Word64
bufSize :: Int
bufState :: BufferState
bufRaw :: RawBuffer Word8
bufState :: forall e. Buffer e -&gt; BufferState
bufSize :: forall e. Buffer e -&gt; Int
bufRaw :: forall e. Buffer e -&gt; RawBuffer e
bufR :: forall e. Buffer e -&gt; Int
bufOffset :: forall e. Buffer e -&gt; Word64
bufL :: forall e. Buffer e -&gt; Int
</span><a href="#local-6989586621679546893"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer :: forall e.
RawBuffer e
-&gt; BufferState -&gt; Int -&gt; Word64 -&gt; Int -&gt; Int -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufState :: BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var">bufState</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679546897"><span class="hs-identifier hs-var">bufState</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufRaw :: RawBuffer CWchar
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8 -&gt; RawBuffer CWchar
forall a b. ForeignPtr a -&gt; ForeignPtr b
</span><a href="GHC.ForeignPtr.html#castForeignPtr"><span class="hs-identifier hs-var">castForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679546898"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int
forall {a}. Integral a =&gt; a -&gt; a
</span><a href="#local-6989586621679546892"><span class="hs-identifier hs-var">half</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546896"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufOffset :: Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679546895"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int
forall {a}. Integral a =&gt; a -&gt; a
</span><a href="#local-6989586621679546892"><span class="hs-identifier hs-var">half</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546894"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int
forall {a}. Integral a =&gt; a -&gt; a
</span><a href="#local-6989586621679546892"><span class="hs-identifier hs-var">half</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546893"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-187"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679546892"><span class="annot"><span class="annottext">half :: a -&gt; a
</span><a href="#local-6989586621679546892"><span class="hs-identifier hs-var hs-var">half</span></a></span></span><span> </span><span id="local-6989586621679546878"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546878"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546878"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; (a, a)
forall a. Integral a =&gt; a -&gt; a -&gt; (a, a)
</span><a href="GHC.Real.html#divMod"><span class="hs-operator hs-var">`divMod`</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">2</span></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679546876"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546876"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546876"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-188"></span><span>                                      </span><span class="annot"><span class="annottext">(a, a)
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; a
forall a. String -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;cwcharView: utf16_(encode|decode) (wrote out|consumed) non multiple-of-2 number of bytes&quot;</span></span><span>
</span><span id="line-189"></span><span>
</span><span id="line-190"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_encode"><span class="hs-identifier hs-type">utf16_native_encode</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#CodeBuffer"><span class="hs-identifier hs-type">CodeBuffer</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span>
</span><span id="line-191"></span><span id="utf16_native_encode"><span class="annot"><span class="annottext">utf16_native_encode :: CodeBuffer Char CWchar
</span><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_encode"><span class="hs-identifier hs-var hs-var">utf16_native_encode</span></a></span></span><span> </span><span id="local-6989586621679546874"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546874"><span class="hs-identifier hs-var">ibuf</span></a></span></span><span> </span><span id="local-6989586621679546873"><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546873"><span class="hs-identifier hs-var">obuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-192"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679546872"><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546872"><span class="hs-identifier hs-var">why</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546871"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546871"><span class="hs-identifier hs-var">ibuf</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546870"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546870"><span class="hs-identifier hs-var">obuf</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CodeBuffer Char Word8
</span><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_encode%27"><span class="hs-identifier hs-var">utf16_native_encode'</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546874"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer CWchar -&gt; Buffer Word8
</span><a href="GHC.IO.Encoding.CodePage.API.html#byteView"><span class="hs-identifier hs-var">byteView</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546873"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-193"></span><span>  </span><span class="annot"><span class="annottext">(CodingProgress, Buffer Char, Buffer CWchar)
-&gt; IO (CodingProgress, Buffer Char, Buffer CWchar)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546872"><span class="hs-identifier hs-var">why</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546871"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Buffer CWchar
</span><a href="GHC.IO.Encoding.CodePage.API.html#cwcharView"><span class="hs-identifier hs-var">cwcharView</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546870"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-194"></span><span>
</span><span id="line-195"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_decode"><span class="hs-identifier hs-type">utf16_native_decode</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#CodeBuffer"><span class="hs-identifier hs-type">CodeBuffer</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span>
</span><span id="line-196"></span><span id="utf16_native_decode"><span class="annot"><span class="annottext">utf16_native_decode :: CodeBuffer CWchar Char
</span><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_decode"><span class="hs-identifier hs-var hs-var">utf16_native_decode</span></a></span></span><span> </span><span id="local-6989586621679546868"><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546868"><span class="hs-identifier hs-var">ibuf</span></a></span></span><span> </span><span id="local-6989586621679546867"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546867"><span class="hs-identifier hs-var">obuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-197"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679546866"><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546866"><span class="hs-identifier hs-var">why</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546865"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546865"><span class="hs-identifier hs-var">ibuf</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546864"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546864"><span class="hs-identifier hs-var">obuf</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CodeBuffer Word8 Char
</span><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_decode%27"><span class="hs-identifier hs-var">utf16_native_decode'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer CWchar -&gt; Buffer Word8
</span><a href="GHC.IO.Encoding.CodePage.API.html#byteView"><span class="hs-identifier hs-var">byteView</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546868"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546867"><span class="hs-identifier hs-var">obuf</span></a></span><span>
</span><span id="line-198"></span><span>  </span><span class="annot"><span class="annottext">(CodingProgress, Buffer CWchar, Buffer Char)
-&gt; IO (CodingProgress, Buffer CWchar, Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546866"><span class="hs-identifier hs-var">why</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Buffer CWchar
</span><a href="GHC.IO.Encoding.CodePage.API.html#cwcharView"><span class="hs-identifier hs-var">cwcharView</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546865"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546864"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-199"></span><span>
</span><span id="line-200"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#cpDecode"><span class="hs-identifier hs-type">cpDecode</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Word.html#Word32"><span class="hs-identifier hs-type">Word32</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#DecodeBuffer"><span class="hs-identifier hs-type">DecodeBuffer</span></a></span><span>
</span><span id="line-201"></span><span id="cpDecode"><span class="annot"><span class="annottext">cpDecode :: Word32 -&gt; Int -&gt; CodeBuffer Word8 Char
</span><a href="GHC.IO.Encoding.CodePage.API.html#cpDecode"><span class="hs-identifier hs-var hs-var">cpDecode</span></a></span></span><span> </span><span id="local-6989586621679546863"><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546863"><span class="hs-identifier hs-var">cp</span></a></span></span><span> </span><span id="local-6989586621679546862"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546862"><span class="hs-identifier hs-var">max_char_size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679546861"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546861"><span class="hs-identifier hs-var">ibuf</span></a></span></span><span> </span><span id="local-6989586621679546860"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546860"><span class="hs-identifier hs-var">obuf</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span class="hs-cpp">
#if defined(CHARBUF_UTF16)
</span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">mbuf</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">obuf</span><span class="hs-cpp">
#else
</span><span>    </span><span class="hs-comment">-- FIXME: share the buffer between runs, even if the buffer is not the perfect size</span><span>
</span><span id="line-206"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679546853"><span class="annot"><span class="annottext">sz :: Int
</span><a href="#local-6989586621679546853"><span class="hs-identifier hs-var hs-var">sz</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>       </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546861"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">)</span><span>     </span><span class="hs-comment">-- I guess in the worst case the input CP text consists of 1-byte sequences that map entirely to things outside the BMP and so require 2 UTF-16 chars</span><span>
</span><span id="line-207"></span><span>             </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Ord a =&gt; a -&gt; a -&gt; a
</span><a href="../../ghc-prim/src/GHC.Classes.html#min"><span class="hs-operator hs-var">`min`</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferAvailable"><span class="hs-identifier hs-var">bufferAvailable</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546860"><span class="hs-identifier hs-var">obuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- In the best case, each pair of UTF-16 points becomes a single UTF-32 point</span><span>
</span><span id="line-208"></span><span>    </span><span id="local-6989586621679546850"><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546850"><span class="hs-identifier hs-var">mbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; BufferState -&gt; IO (Buffer CWchar)
forall e. Int -&gt; Int -&gt; BufferState -&gt; IO (Buffer e)
</span><a href="GHC.IO.Buffer.html#newBuffer"><span class="hs-identifier hs-var">newBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546853"><span class="hs-identifier hs-var">sz</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546853"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CWchar"><span class="hs-identifier hs-type">CWchar</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>    </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;cpDecode &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546861"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546850"><span class="hs-identifier hs-var">mbuf</span></a></span><span>
</span><span id="line-211"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679546846"><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546846"><span class="hs-identifier hs-var">why1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546845"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546845"><span class="hs-identifier hs-var">ibuf'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546844"><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546844"><span class="hs-identifier hs-var">mbuf'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Ptr Word8 -&gt; Int -&gt; Ptr CWchar -&gt; Int -&gt; IO (Either Bool Int))
-&gt; (Word8 -&gt; IO Bool)
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; CodeBuffer Word8 CWchar
forall from to.
Storable from =&gt;
(Ptr from -&gt; Int -&gt; Ptr to -&gt; Int -&gt; IO (Either Bool Int))
-&gt; (from -&gt; IO Bool)
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; CodeBuffer from to
</span><a href="GHC.IO.Encoding.CodePage.API.html#cpRecode"><span class="hs-identifier hs-var">cpRecode</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr CWchar -&gt; Int -&gt; IO (Either Bool Int)
forall {a} {a} {b}.
(Integral a, Integral a, Show a, Show a, Num b) =&gt;
Ptr Word8 -&gt; a -&gt; Ptr CWchar -&gt; a -&gt; IO (Either Bool b)
</span><a href="#local-6989586621679546842"><span class="hs-identifier hs-var">try'</span></a></span><span> </span><span class="annot"><span class="annottext">Word8 -&gt; IO Bool
</span><a href="#local-6989586621679546841"><span class="hs-identifier hs-var">is_valid_prefix</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546862"><span class="hs-identifier hs-var">max_char_size</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546861"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546850"><span class="hs-identifier hs-var">mbuf</span></a></span><span>
</span><span id="line-212"></span><span>    </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;cpRecode (cpDecode) = &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">CodingProgress -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546846"><span class="hs-identifier hs-var">why1</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546845"><span class="hs-identifier hs-var">ibuf'</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546844"><span class="hs-identifier hs-var">mbuf'</span></a></span><span class="hs-cpp">
#if defined(CHARBUF_UTF16)
</span><span>    </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">why1</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ibuf'</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">mbuf'</span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span>    </span><span class="hs-comment">-- Convert as much UTF-16 as possible to UTF-32. Note that it's impossible for this to fail</span><span>
</span><span id="line-217"></span><span>    </span><span class="hs-comment">-- due to illegal characters since the output from Window's encoding function should be correct UTF-16.</span><span>
</span><span id="line-218"></span><span>    </span><span class="hs-comment">-- However, it's perfectly possible to run out of either output or input buffer.</span><span>
</span><span id="line-219"></span><span>    </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;utf16_native_decode &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546844"><span class="hs-identifier hs-var">mbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546860"><span class="hs-identifier hs-var">obuf</span></a></span><span>
</span><span id="line-220"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679546840"><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546840"><span class="hs-identifier hs-var">why2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546839"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546839"><span class="hs-identifier hs-var">target_utf16_count</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546838"><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546838"><span class="hs-identifier hs-var">mbuf'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546837"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546837"><span class="hs-identifier hs-var">obuf</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CodeBuffer CWchar Char
-&gt; Buffer CWchar
-&gt; Buffer Char
-&gt; IO (CodingProgress, Int, Buffer CWchar, Buffer Char)
forall from to.
CodeBuffer from to
-&gt; Buffer from
-&gt; Buffer to
-&gt; IO (CodingProgress, Int, Buffer from, Buffer to)
</span><a href="GHC.IO.Encoding.CodePage.API.html#saner"><span class="hs-identifier hs-var">saner</span></a></span><span> </span><span class="annot"><span class="annottext">CodeBuffer CWchar Char
</span><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_decode"><span class="hs-identifier hs-var">utf16_native_decode</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546844"><span class="hs-identifier hs-var">mbuf'</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufState :: BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var">bufState</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546860"><span class="hs-identifier hs-var">obuf</span></a></span><span>
</span><span id="line-221"></span><span>    </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;utf16_native_decode = &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">CodingProgress -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546840"><span class="hs-identifier hs-var">why2</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546838"><span class="hs-identifier hs-var">mbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546837"><span class="hs-identifier hs-var">obuf</span></a></span><span>
</span><span id="line-222"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546840"><span class="hs-identifier hs-var">why2</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-223"></span><span>      </span><span class="hs-comment">-- If we successfully translate all of the UTF-16 buffer, we need to know why we couldn't get any more</span><span>
</span><span id="line-224"></span><span>      </span><span class="hs-comment">-- UTF-16 out of the Windows API</span><span>
</span><span id="line-225"></span><span>      </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#InputUnderflow"><span class="hs-identifier hs-var">InputUnderflow</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Buffer CWchar -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546838"><span class="hs-identifier hs-var">mbuf'</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(CodingProgress, Buffer Word8, Buffer Char)
-&gt; IO (CodingProgress, Buffer Word8, Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546846"><span class="hs-identifier hs-var">why1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546845"><span class="hs-identifier hs-var">ibuf'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546837"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-226"></span><span>                     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO (CodingProgress, Buffer Word8, Buffer Char)
forall a. String -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;cpDecode: impossible underflown UTF-16 buffer&quot;</span></span><span>
</span><span id="line-227"></span><span>      </span><span class="hs-comment">-- InvalidSequence should be impossible since mbuf' is output from Windows.</span><span>
</span><span id="line-228"></span><span>      </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#InvalidSequence"><span class="hs-identifier hs-var">InvalidSequence</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO (CodingProgress, Buffer Word8, Buffer Char)
forall a. String -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;InvalidSequence on output of Windows API&quot;</span></span><span>
</span><span id="line-229"></span><span>      </span><span class="hs-comment">-- If we run out of space in obuf, we need to ask for more output buffer space, while also returning</span><span>
</span><span id="line-230"></span><span>      </span><span class="hs-comment">-- the characters we have managed to consume so far.</span><span>
</span><span id="line-231"></span><span>      </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#OutputUnderflow"><span class="hs-identifier hs-var">OutputUnderflow</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-232"></span><span>        </span><span class="hs-comment">-- We have an interesting problem here similar to the cpEncode case where we have to figure out how much</span><span>
</span><span id="line-233"></span><span>        </span><span class="hs-comment">-- of the byte buffer was consumed to reach as far as the last UTF-16 character we actually decoded to UTF-32 OK.</span><span>
</span><span id="line-234"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-235"></span><span>        </span><span class="hs-comment">-- The minimum number of bytes it could take is half the number of UTF-16 chars we got on the output, since</span><span>
</span><span id="line-236"></span><span>        </span><span class="hs-comment">-- one byte could theoretically generate two UTF-16 characters.</span><span>
</span><span id="line-237"></span><span>        </span><span class="hs-comment">-- The common case (ASCII text) is that every byte in the input maps to a single UTF-16 character.</span><span>
</span><span id="line-238"></span><span>        </span><span class="hs-comment">-- In the worst case max_char_size bytes map to each UTF-16 character.</span><span>
</span><span id="line-239"></span><span>        </span><span id="local-6989586621679546833"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546833"><span class="hs-identifier hs-var">byte_count</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String
-&gt; CodeBuffer Word8 CWchar
-&gt; Buffer Word8
-&gt; Buffer CWchar
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; IO Int
forall from to.
String
-&gt; CodeBuffer from to
-&gt; Buffer from
-&gt; Buffer to
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; IO Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#bSearch"><span class="hs-identifier hs-var">bSearch</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;cpDecode&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Ptr Word8 -&gt; Int -&gt; Ptr CWchar -&gt; Int -&gt; IO (Either Bool Int))
-&gt; (Word8 -&gt; IO Bool)
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; CodeBuffer Word8 CWchar
forall from to.
Storable from =&gt;
(Ptr from -&gt; Int -&gt; Ptr to -&gt; Int -&gt; IO (Either Bool Int))
-&gt; (from -&gt; IO Bool)
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; CodeBuffer from to
</span><a href="GHC.IO.Encoding.CodePage.API.html#cpRecode"><span class="hs-identifier hs-var">cpRecode</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr CWchar -&gt; Int -&gt; IO (Either Bool Int)
forall {a} {a} {b}.
(Integral a, Integral a, Show a, Show a, Num b) =&gt;
Ptr Word8 -&gt; a -&gt; Ptr CWchar -&gt; a -&gt; IO (Either Bool b)
</span><a href="#local-6989586621679546842"><span class="hs-identifier hs-var">try'</span></a></span><span> </span><span class="annot"><span class="annottext">Word8 -&gt; IO Bool
</span><a href="#local-6989586621679546841"><span class="hs-identifier hs-var">is_valid_prefix</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546862"><span class="hs-identifier hs-var">max_char_size</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546861"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546850"><span class="hs-identifier hs-var">mbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546839"><span class="hs-identifier hs-var">target_utf16_count</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546839"><span class="hs-identifier hs-var">target_utf16_count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Real.html#div"><span class="hs-operator hs-var">`div`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546839"><span class="hs-identifier hs-var">target_utf16_count</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546839"><span class="hs-identifier hs-var">target_utf16_count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546862"><span class="hs-identifier hs-var">max_char_size</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-240"></span><span>        </span><span class="annot"><span class="annottext">(CodingProgress, Buffer Word8, Buffer Char)
-&gt; IO (CodingProgress, Buffer Word8, Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#OutputUnderflow"><span class="hs-identifier hs-var">OutputUnderflow</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Word8 -&gt; Buffer Word8
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferRemove"><span class="hs-identifier hs-var">bufferRemove</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546833"><span class="hs-identifier hs-var">byte_count</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546861"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546837"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-243"></span><span>    </span><span id="local-6989586621679546841"><span class="annot"><span class="annottext">is_valid_prefix :: Word8 -&gt; IO Bool
</span><a href="#local-6989586621679546841"><span class="hs-identifier hs-var hs-var">is_valid_prefix</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; Word8 -&gt; IO Bool
</span><a href="GHC.IO.Encoding.CodePage.API.html#c_IsDBCSLeadByteEx"><span class="hs-identifier hs-var">c_IsDBCSLeadByteEx</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546863"><span class="hs-identifier hs-var">cp</span></a></span><span>
</span><span id="line-244"></span><span>    </span><span id="local-6989586621679546842"><span class="annot"><span class="annottext">try' :: Ptr Word8 -&gt; a -&gt; Ptr CWchar -&gt; a -&gt; IO (Either Bool b)
</span><a href="#local-6989586621679546842"><span class="hs-identifier hs-var hs-var">try'</span></a></span></span><span> </span><span id="local-6989586621679546783"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679546783"><span class="hs-identifier hs-var">iptr</span></a></span></span><span> </span><span id="local-6989586621679546782"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546782"><span class="hs-identifier hs-var">icnt</span></a></span></span><span> </span><span id="local-6989586621679546781"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679546781"><span class="hs-identifier hs-var">optr</span></a></span></span><span> </span><span id="local-6989586621679546780"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546780"><span class="hs-identifier hs-var">ocnt</span></a></span></span><span>
</span><span id="line-245"></span><span>     </span><span class="hs-comment">-- MultiByteToWideChar does surprising things if you have ocnt == 0</span><span>
</span><span id="line-246"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546780"><span class="hs-identifier hs-var">ocnt</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Either Bool b -&gt; IO (Either Bool b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Either Bool b
forall a b. a -&gt; Either a b
</span><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-247"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-248"></span><span>        </span><span id="local-6989586621679546779"><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679546779"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Word32
-&gt; Word32 -&gt; Ptr Word8 -&gt; CInt -&gt; Ptr CWchar -&gt; CInt -&gt; IO CInt
</span><a href="GHC.IO.Encoding.CodePage.API.html#c_MultiByteToWideChar"><span class="hs-identifier hs-var">c_MultiByteToWideChar</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word32 -&gt; Word32
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546863"><span class="hs-identifier hs-var">cp</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word32
</span><span class="hs-number">8</span></span><span> </span><span class="hs-comment">-- MB_ERR_INVALID_CHARS == 8: Fail if an invalid input character is encountered</span><span>
</span><span id="line-249"></span><span>                                     </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679546783"><span class="hs-identifier hs-var">iptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; CInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546782"><span class="hs-identifier hs-var">icnt</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679546781"><span class="hs-identifier hs-var">optr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; CInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546780"><span class="hs-identifier hs-var">ocnt</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-250"></span><span>        </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;MultiByteToWideChar &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546863"><span class="hs-identifier hs-var">cp</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; 8 &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679546783"><span class="hs-identifier hs-var">iptr</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546782"><span class="hs-identifier hs-var">icnt</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679546781"><span class="hs-identifier hs-var">optr</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546780"><span class="hs-identifier hs-var">ocnt</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;\n = &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">CInt -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679546779"><span class="hs-identifier hs-var">err</span></a></span><span>
</span><span id="line-251"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679546779"><span class="hs-identifier hs-var">err</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-252"></span><span>          </span><span class="hs-comment">-- 0 indicates that we did not succeed</span><span>
</span><span id="line-253"></span><span>          </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-254"></span><span>            </span><span id="local-6989586621679546778"><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546778"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO Word32
</span><a href="GHC.Windows.html#getLastError"><span class="hs-identifier hs-var">getLastError</span></a></span><span>
</span><span id="line-255"></span><span>            </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546778"><span class="hs-identifier hs-var">err</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-256"></span><span>                </span><span class="annot"><span class="annottext">Word32
</span><span class="hs-number">122</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either Bool b -&gt; IO (Either Bool b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Either Bool b
forall a b. a -&gt; Either a b
</span><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-257"></span><span>                </span><span class="annot"><span class="annottext">Word32
</span><span class="hs-number">1113</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either Bool b -&gt; IO (Either Bool b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Either Bool b
forall a b. a -&gt; Either a b
</span><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-258"></span><span>                </span><span class="annot"><span class="annottext">Word32
</span><span class="hs-identifier">_</span></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; Word32 -&gt; IO (Either Bool b)
forall a. String -&gt; Word32 -&gt; IO a
</span><a href="GHC.Windows.html#failWith"><span class="hs-identifier hs-var">failWith</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;MultiByteToWideChar&quot;</span></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546778"><span class="hs-identifier hs-var">err</span></a></span><span>
</span><span id="line-259"></span><span>          </span><span id="local-6989586621679546775"><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679546775"><span class="hs-identifier hs-var">wrote_chars</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either Bool b -&gt; IO (Either Bool b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b -&gt; Either Bool b
forall a b. b -&gt; Either a b
</span><a href="Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CInt -&gt; b
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679546775"><span class="hs-identifier hs-var">wrote_chars</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-260"></span><span>
</span><span id="line-261"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#cpEncode"><span class="hs-identifier hs-type">cpEncode</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Word.html#Word32"><span class="hs-identifier hs-type">Word32</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#EncodeBuffer"><span class="hs-identifier hs-type">EncodeBuffer</span></a></span><span>
</span><span id="line-262"></span><span id="cpEncode"><span class="annot"><span class="annottext">cpEncode :: Word32 -&gt; Int -&gt; CodeBuffer Char Word8
</span><a href="GHC.IO.Encoding.CodePage.API.html#cpEncode"><span class="hs-identifier hs-var hs-var">cpEncode</span></a></span></span><span> </span><span id="local-6989586621679546774"><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546774"><span class="hs-identifier hs-var">cp</span></a></span></span><span> </span><span id="local-6989586621679546773"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546773"><span class="hs-identifier hs-var">_max_char_size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679546772"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546772"><span class="hs-identifier hs-var">ibuf</span></a></span></span><span> </span><span id="local-6989586621679546771"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546771"><span class="hs-identifier hs-var">obuf</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span class="hs-cpp">
#if defined(CHARBUF_UTF16)
</span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">mbuf'</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ibuf</span><span class="hs-cpp">
#else
</span><span>    </span><span class="hs-comment">-- FIXME: share the buffer between runs, even though that means we can't size the buffer as we want.</span><span>
</span><span id="line-267"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679546765"><span class="annot"><span class="annottext">sz :: Int
</span><a href="#local-6989586621679546765"><span class="hs-identifier hs-var hs-var">sz</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>       </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546772"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">)</span><span>     </span><span class="hs-comment">-- UTF-32 always uses 4 bytes. UTF-16 uses at most 4 bytes.</span><span>
</span><span id="line-268"></span><span>             </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Ord a =&gt; a -&gt; a -&gt; a
</span><a href="../../ghc-prim/src/GHC.Classes.html#min"><span class="hs-operator hs-var">`min`</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferAvailable"><span class="hs-identifier hs-var">bufferAvailable</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546771"><span class="hs-identifier hs-var">obuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- In the best case, each pair of UTF-16 points fits into only 1 byte</span><span>
</span><span id="line-269"></span><span>    </span><span id="local-6989586621679546764"><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546764"><span class="hs-identifier hs-var">mbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; BufferState -&gt; IO (Buffer CWchar)
forall e. Int -&gt; Int -&gt; BufferState -&gt; IO (Buffer e)
</span><a href="GHC.IO.Buffer.html#newBuffer"><span class="hs-identifier hs-var">newBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546765"><span class="hs-identifier hs-var">sz</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546765"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span>
</span><span id="line-270"></span><span>
</span><span id="line-271"></span><span>    </span><span class="hs-comment">-- Convert as much UTF-32 as possible to UTF-16. NB: this can't fail due to output underflow</span><span>
</span><span id="line-272"></span><span>    </span><span class="hs-comment">-- since we sized the output buffer correctly. However, it could fail due to an illegal character</span><span>
</span><span id="line-273"></span><span>    </span><span class="hs-comment">-- in the input if it encounters a lone surrogate. In this case, our recovery will be applied as normal.</span><span>
</span><span id="line-274"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679546763"><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546763"><span class="hs-identifier hs-var">why1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546762"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546762"><span class="hs-identifier hs-var">ibuf'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546761"><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546761"><span class="hs-identifier hs-var">mbuf'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CodeBuffer Char CWchar
</span><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_encode"><span class="hs-identifier hs-var">utf16_native_encode</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546772"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546764"><span class="hs-identifier hs-var">mbuf</span></a></span><span class="hs-cpp">
#endif
</span><span>    </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;\ncpEncode &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546761"><span class="hs-identifier hs-var">mbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546771"><span class="hs-identifier hs-var">obuf</span></a></span><span>
</span><span id="line-277"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679546760"><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546760"><span class="hs-identifier hs-var">why2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546759"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546759"><span class="hs-identifier hs-var">target_utf16_count</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546758"><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546758"><span class="hs-identifier hs-var">mbuf'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546757"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546757"><span class="hs-identifier hs-var">obuf</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CodeBuffer CWchar Word8
-&gt; Buffer CWchar
-&gt; Buffer Word8
-&gt; IO (CodingProgress, Int, Buffer CWchar, Buffer Word8)
forall from to.
CodeBuffer from to
-&gt; Buffer from
-&gt; Buffer to
-&gt; IO (CodingProgress, Int, Buffer from, Buffer to)
</span><a href="GHC.IO.Encoding.CodePage.API.html#saner"><span class="hs-identifier hs-var">saner</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Ptr CWchar -&gt; Int -&gt; Ptr Word8 -&gt; Int -&gt; IO (Either Bool Int))
-&gt; (CWchar -&gt; IO Bool)
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; CodeBuffer CWchar Word8
forall from to.
Storable from =&gt;
(Ptr from -&gt; Int -&gt; Ptr to -&gt; Int -&gt; IO (Either Bool Int))
-&gt; (from -&gt; IO Bool)
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; CodeBuffer from to
</span><a href="GHC.IO.Encoding.CodePage.API.html#cpRecode"><span class="hs-identifier hs-var">cpRecode</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; Int -&gt; Ptr Word8 -&gt; Int -&gt; IO (Either Bool Int)
forall {a} {a} {b}.
(Integral a, Integral a, Show a, Show a, Num b) =&gt;
Ptr CWchar -&gt; a -&gt; Ptr Word8 -&gt; a -&gt; IO (Either Bool b)
</span><a href="#local-6989586621679546756"><span class="hs-identifier hs-var">try'</span></a></span><span> </span><span class="annot"><span class="annottext">CWchar -&gt; IO Bool
forall {m :: * -&gt; *} {p}. Monad m =&gt; p -&gt; m Bool
</span><a href="#local-6989586621679546755"><span class="hs-identifier hs-var">is_valid_prefix</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546761"><span class="hs-identifier hs-var">mbuf'</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufState :: BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var">bufState</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546771"><span class="hs-identifier hs-var">obuf</span></a></span><span>
</span><span id="line-278"></span><span>    </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;cpRecode (cpEncode) = &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">CodingProgress -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546760"><span class="hs-identifier hs-var">why2</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546758"><span class="hs-identifier hs-var">mbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546757"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-cpp">
#if defined(CHARBUF_UTF16)
</span><span>    </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">why2</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">mbuf'</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">obuf</span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546760"><span class="hs-identifier hs-var">why2</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-283"></span><span>      </span><span class="hs-comment">-- If we successfully translate all of the UTF-16 buffer, we need to know why</span><span>
</span><span id="line-284"></span><span>      </span><span class="hs-comment">-- we weren't able to get any more UTF-16 out of the UTF-32 buffer</span><span>
</span><span id="line-285"></span><span>      </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#InputUnderflow"><span class="hs-identifier hs-var">InputUnderflow</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Buffer CWchar -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546758"><span class="hs-identifier hs-var">mbuf'</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(CodingProgress, Buffer Char, Buffer Word8)
-&gt; IO (CodingProgress, Buffer Char, Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546763"><span class="hs-identifier hs-var">why1</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546762"><span class="hs-identifier hs-var">ibuf'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546757"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-286"></span><span>                     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO (CodingProgress, Buffer Char, Buffer Word8)
forall a. String -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;cpEncode: impossible underflown UTF-16 buffer&quot;</span></span><span>
</span><span id="line-287"></span><span>      </span><span class="hs-comment">-- With OutputUnderflow/InvalidSequence we only care about the failings of the UTF-16-&gt;CP translation.</span><span>
</span><span id="line-288"></span><span>      </span><span class="hs-comment">-- Yes, InvalidSequence is possible even though mbuf' is guaranteed to be valid UTF-16, because</span><span>
</span><span id="line-289"></span><span>      </span><span class="hs-comment">-- the code page may not be able to represent the encoded Unicode codepoint.</span><span>
</span><span id="line-290"></span><span>      </span><span class="annot"><span class="annottext">CodingProgress
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-291"></span><span>        </span><span class="hs-comment">-- Here is an interesting problem. If we have only managed to translate part of the mbuf'</span><span>
</span><span id="line-292"></span><span>        </span><span class="hs-comment">-- then we need to return an ibuf which has consumed exactly those bytes required to obtain</span><span>
</span><span id="line-293"></span><span>        </span><span class="hs-comment">-- that part of the mbuf'. To reconstruct this information, we binary search for the number of</span><span>
</span><span id="line-294"></span><span>        </span><span class="hs-comment">-- UTF-32 characters required to get the consumed count of UTF-16 characters:</span><span>
</span><span id="line-295"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-296"></span><span>        </span><span class="hs-comment">-- When dealing with data from the BMP (the common case), consuming N UTF-16 characters will be the same as consuming N</span><span>
</span><span id="line-297"></span><span>        </span><span class="hs-comment">-- UTF-32 characters. We start our search there so that most binary searches will terminate in a single iteration.</span><span>
</span><span id="line-298"></span><span>        </span><span class="hs-comment">-- Furthermore, the absolute minimum number of UTF-32 characters this can correspond to is 1/2 the UTF-16 byte count</span><span>
</span><span id="line-299"></span><span>        </span><span class="hs-comment">-- (this will be realised when the input data is entirely not in the BMP).</span><span>
</span><span id="line-300"></span><span>        </span><span id="local-6989586621679546754"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546754"><span class="hs-identifier hs-var">utf32_count</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String
-&gt; CodeBuffer Char CWchar
-&gt; Buffer Char
-&gt; Buffer CWchar
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; IO Int
forall from to.
String
-&gt; CodeBuffer from to
-&gt; Buffer from
-&gt; Buffer to
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; IO Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#bSearch"><span class="hs-identifier hs-var">bSearch</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;cpEncode&quot;</span></span><span> </span><span class="annot"><span class="annottext">CodeBuffer Char CWchar
</span><a href="GHC.IO.Encoding.CodePage.API.html#utf16_native_encode"><span class="hs-identifier hs-var">utf16_native_encode</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546772"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer CWchar
</span><a href="#local-6989586621679546764"><span class="hs-identifier hs-var">mbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546759"><span class="hs-identifier hs-var">target_utf16_count</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546759"><span class="hs-identifier hs-var">target_utf16_count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Real.html#div"><span class="hs-operator hs-var">`div`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546759"><span class="hs-identifier hs-var">target_utf16_count</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546759"><span class="hs-identifier hs-var">target_utf16_count</span></a></span><span>
</span><span id="line-301"></span><span>        </span><span class="annot"><span class="annottext">(CodingProgress, Buffer Char, Buffer Word8)
-&gt; IO (CodingProgress, Buffer Char, Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546760"><span class="hs-identifier hs-var">why2</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Char -&gt; Buffer Char
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferRemove"><span class="hs-identifier hs-var">bufferRemove</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546754"><span class="hs-identifier hs-var">utf32_count</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679546772"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679546757"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-304"></span><span>    </span><span class="hs-comment">-- Single characters should be mappable to bytes. If they aren't supported by the CP then we have an invalid input sequence.</span><span>
</span><span id="line-305"></span><span>    </span><span id="local-6989586621679546755"><span class="annot"><span class="annottext">is_valid_prefix :: p -&gt; m Bool
</span><a href="#local-6989586621679546755"><span class="hs-identifier hs-var hs-var">is_valid_prefix</span></a></span></span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; m Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-306"></span><span>
</span><span id="line-307"></span><span>    </span><span id="local-6989586621679546756"><span class="annot"><span class="annottext">try' :: Ptr CWchar -&gt; a -&gt; Ptr Word8 -&gt; a -&gt; IO (Either Bool b)
</span><a href="#local-6989586621679546756"><span class="hs-identifier hs-var hs-var">try'</span></a></span></span><span> </span><span id="local-6989586621679546702"><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679546702"><span class="hs-identifier hs-var">iptr</span></a></span></span><span> </span><span id="local-6989586621679546701"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546701"><span class="hs-identifier hs-var">icnt</span></a></span></span><span> </span><span id="local-6989586621679546700"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679546700"><span class="hs-identifier hs-var">optr</span></a></span></span><span> </span><span id="local-6989586621679546699"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546699"><span class="hs-identifier hs-var">ocnt</span></a></span></span><span>
</span><span id="line-308"></span><span>     </span><span class="hs-comment">-- WideCharToMultiByte does surprising things if you call it with ocnt == 0</span><span>
</span><span id="line-309"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546699"><span class="hs-identifier hs-var">ocnt</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; a -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Either Bool b -&gt; IO (Either Bool b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Either Bool b
forall a b. a -&gt; Either a b
</span><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-310"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Ptr Bool -&gt; IO (Either Bool b)) -&gt; IO (Either Bool b)
forall a b. Storable a =&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="Foreign.Marshal.Alloc.html#alloca"><span class="hs-identifier hs-var">alloca</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Bool -&gt; IO (Either Bool b)) -&gt; IO (Either Bool b))
-&gt; (Ptr Bool -&gt; IO (Either Bool b)) -&gt; IO (Either Bool b)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679546698"><span class="annot"><span class="annottext">Ptr Bool
</span><a href="#local-6989586621679546698"><span class="hs-identifier hs-var">defaulted_ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-311"></span><span>      </span><span class="annot"><span class="annottext">Ptr Bool -&gt; Bool -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; a -&gt; IO ()
</span><a href="Foreign.Storable.html#poke"><span class="hs-identifier hs-var">poke</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Bool
</span><a href="#local-6989586621679546698"><span class="hs-identifier hs-var">defaulted_ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-312"></span><span>      </span><span id="local-6989586621679546697"><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679546697"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Word32
-&gt; Word32
-&gt; Ptr CWchar
-&gt; CInt
-&gt; Ptr Word8
-&gt; CInt
-&gt; Ptr Word8
-&gt; Ptr Bool
-&gt; IO CInt
</span><a href="GHC.IO.Encoding.CodePage.API.html#c_WideCharToMultiByte"><span class="hs-identifier hs-var">c_WideCharToMultiByte</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word32 -&gt; Word32
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546774"><span class="hs-identifier hs-var">cp</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word32
</span><span class="hs-number">0</span></span><span> </span><span class="hs-comment">-- NB: the WC_ERR_INVALID_CHARS flag is useless: only has an effect with the UTF-8 code page</span><span>
</span><span id="line-313"></span><span>                                   </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679546702"><span class="hs-identifier hs-var">iptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; CInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546701"><span class="hs-identifier hs-var">icnt</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679546700"><span class="hs-identifier hs-var">optr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; CInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546699"><span class="hs-identifier hs-var">ocnt</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-314"></span><span>                                   </span><span class="annot"><span class="annottext">Ptr Word8
forall a. Ptr a
</span><a href="GHC.Ptr.html#nullPtr"><span class="hs-identifier hs-var">nullPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Bool
</span><a href="#local-6989586621679546698"><span class="hs-identifier hs-var">defaulted_ptr</span></a></span><span>
</span><span id="line-315"></span><span>      </span><span id="local-6989586621679546695"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546695"><span class="hs-identifier hs-var">defaulted</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Bool -&gt; IO Bool
forall a. Storable a =&gt; Ptr a -&gt; IO a
</span><a href="Foreign.Storable.html#peek"><span class="hs-identifier hs-var">peek</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Bool
</span><a href="#local-6989586621679546698"><span class="hs-identifier hs-var">defaulted_ptr</span></a></span><span>
</span><span id="line-316"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;WideCharToMultiByte &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Word32 -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546774"><span class="hs-identifier hs-var">cp</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; 0 &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CWchar
</span><a href="#local-6989586621679546702"><span class="hs-identifier hs-var">iptr</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546701"><span class="hs-identifier hs-var">icnt</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679546700"><span class="hs-identifier hs-var">optr</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546699"><span class="hs-identifier hs-var">ocnt</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; NULL &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Bool -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Bool
</span><a href="#local-6989586621679546698"><span class="hs-identifier hs-var">defaulted_ptr</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;\n = &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">CInt -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679546697"><span class="hs-identifier hs-var">err</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;, &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546695"><span class="hs-identifier hs-var">defaulted</span></a></span><span>
</span><span id="line-317"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679546697"><span class="hs-identifier hs-var">err</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-318"></span><span>          </span><span class="hs-comment">-- 0 indicates that we did not succeed</span><span>
</span><span id="line-319"></span><span>          </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-320"></span><span>            </span><span id="local-6989586621679546694"><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546694"><span class="hs-identifier hs-var">err</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO Word32
</span><a href="GHC.Windows.html#getLastError"><span class="hs-identifier hs-var">getLastError</span></a></span><span>
</span><span id="line-321"></span><span>            </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546694"><span class="hs-identifier hs-var">err</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-322"></span><span>                </span><span class="annot"><span class="annottext">Word32
</span><span class="hs-number">122</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either Bool b -&gt; IO (Either Bool b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Either Bool b
forall a b. a -&gt; Either a b
</span><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-323"></span><span>                </span><span class="annot"><span class="annottext">Word32
</span><span class="hs-number">1113</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either Bool b -&gt; IO (Either Bool b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Either Bool b
forall a b. a -&gt; Either a b
</span><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-324"></span><span>                </span><span class="annot"><span class="annottext">Word32
</span><span class="hs-identifier">_</span></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; Word32 -&gt; IO (Either Bool b)
forall a. String -&gt; Word32 -&gt; IO a
</span><a href="GHC.Windows.html#failWith"><span class="hs-identifier hs-var">failWith</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;WideCharToMultiByte&quot;</span></span><span> </span><span class="annot"><span class="annottext">Word32
</span><a href="#local-6989586621679546694"><span class="hs-identifier hs-var">err</span></a></span><span>
</span><span id="line-325"></span><span>          </span><span id="local-6989586621679546693"><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679546693"><span class="hs-identifier hs-var">wrote_bytes</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546695"><span class="hs-identifier hs-var">defaulted</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either Bool b -&gt; IO (Either Bool b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Either Bool b
forall a b. a -&gt; Either a b
</span><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-326"></span><span>                      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either Bool b -&gt; IO (Either Bool b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b -&gt; Either Bool b
forall a b. b -&gt; Either a b
</span><a href="Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CInt -&gt; b
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><a href="#local-6989586621679546693"><span class="hs-identifier hs-var">wrote_bytes</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-327"></span><span>
</span><span id="line-328"></span><span id="local-6989586621679547207"><span id="local-6989586621679547208"><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#bSearch"><span class="hs-identifier hs-type">bSearch</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-329"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#CodeBuffer"><span class="hs-identifier hs-type">CodeBuffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547208"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547207"><span class="hs-identifier hs-type">to</span></a></span><span>
</span><span id="line-330"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547208"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547207"><span class="hs-identifier hs-type">to</span></a></span><span> </span><span class="hs-comment">-- From buffer (crucial data source) and to buffer (temporary storage only). To buffer must be empty (L=R).</span><span>
</span><span id="line-331"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>               </span><span class="hs-comment">-- Target size of to buffer</span><span>
</span><span id="line-332"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-comment">-- Binary search min, mid, max</span><span>
</span><span id="line-333"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span></span><span>            </span><span class="hs-comment">-- Size of from buffer required to reach target size of to buffer</span><span>
</span><span id="line-334"></span><span id="bSearch"><span class="annot"><span class="annottext">bSearch :: forall from to.
String
-&gt; CodeBuffer from to
-&gt; Buffer from
-&gt; Buffer to
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; IO Int
</span><a href="GHC.IO.Encoding.CodePage.API.html#bSearch"><span class="hs-identifier hs-var hs-var">bSearch</span></a></span></span><span> </span><span id="local-6989586621679546692"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679546692"><span class="hs-identifier hs-var">msg</span></a></span></span><span> </span><span id="local-6989586621679546691"><span class="annot"><span class="annottext">CodeBuffer from to
</span><a href="#local-6989586621679546691"><span class="hs-identifier hs-var">code</span></a></span></span><span> </span><span id="local-6989586621679546690"><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546690"><span class="hs-identifier hs-var">ibuf</span></a></span></span><span> </span><span id="local-6989586621679546689"><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546689"><span class="hs-identifier hs-var">mbuf</span></a></span></span><span> </span><span id="local-6989586621679546688"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546688"><span class="hs-identifier hs-var">target_to_elems</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="#local-6989586621679546687"><span class="hs-identifier hs-var">go</span></a></span><span>
</span><span id="line-335"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-336"></span><span>    </span><span id="local-6989586621679546687"><span class="annot"><span class="annottext">go :: Int -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="#local-6989586621679546687"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621679546661"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546661"><span class="hs-identifier hs-var">mn</span></a></span></span><span> </span><span id="local-6989586621679546660"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546660"><span class="hs-identifier hs-var">md</span></a></span></span><span> </span><span id="local-6989586621679546659"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546659"><span class="hs-identifier hs-var">mx</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-337"></span><span>      </span><span class="hs-comment">-- NB: this loop repeatedly reencodes on top of mbuf using a varying fraction of ibuf. It doesn't</span><span>
</span><span id="line-338"></span><span>      </span><span class="hs-comment">-- matter if we blast the contents of mbuf since we already consumed all of the contents we are going to use.</span><span>
</span><span id="line-339"></span><span>      </span><span class="hs-special">(</span><span id="local-6989586621679546658"><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546658"><span class="hs-identifier hs-var">_why</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546657"><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546657"><span class="hs-identifier hs-var">ibuf</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679546656"><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546656"><span class="hs-identifier hs-var">mbuf</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CodeBuffer from to
</span><a href="#local-6989586621679546691"><span class="hs-identifier hs-var">code</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546690"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546690"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546660"><span class="hs-identifier hs-var">md</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546689"><span class="hs-identifier hs-var">mbuf</span></a></span><span>
</span><span id="line-340"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;code (bSearch &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679546692"><span class="hs-identifier hs-var">msg</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;) &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546660"><span class="hs-identifier hs-var">md</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; = &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">CodingProgress -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679546658"><span class="hs-identifier hs-var">_why</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;, &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546657"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546656"><span class="hs-identifier hs-var">mbuf</span></a></span><span>
</span><span id="line-341"></span><span>      </span><span class="hs-comment">-- The normal case is to get InputUnderflow here, which indicates that coding basically</span><span>
</span><span id="line-342"></span><span>      </span><span class="hs-comment">-- terminated normally.</span><span>
</span><span id="line-343"></span><span>      </span><span class="hs-comment">--</span><span>
</span><span id="line-344"></span><span>      </span><span class="hs-comment">-- However, InvalidSequence is also possible if we are being called from cpDecode if we</span><span>
</span><span id="line-345"></span><span>      </span><span class="hs-comment">-- have just been unlucky enough to set md so that ibuf straddles a byte boundary.</span><span>
</span><span id="line-346"></span><span>      </span><span class="hs-comment">-- In this case we have to be really careful, because we don't want to report that</span><span>
</span><span id="line-347"></span><span>      </span><span class="hs-comment">-- &quot;md&quot; elements is the right number when in actual fact we could have had md-1 input</span><span>
</span><span id="line-348"></span><span>      </span><span class="hs-comment">-- elements and still produced the same number of bufferElems in mbuf.</span><span>
</span><span id="line-349"></span><span>      </span><span class="hs-comment">--</span><span>
</span><span id="line-350"></span><span>      </span><span class="hs-comment">-- In fact, we have to worry about this possibility even if we get InputUnderflow</span><span>
</span><span id="line-351"></span><span>      </span><span class="hs-comment">-- since that will report InputUnderflow rather than InvalidSequence if the buffer</span><span>
</span><span id="line-352"></span><span>      </span><span class="hs-comment">-- ends in a valid lead byte. So the expedient thing to do is simply to check if</span><span>
</span><span id="line-353"></span><span>      </span><span class="hs-comment">-- the input buffer was entirely consumed.</span><span>
</span><span id="line-354"></span><span>      </span><span class="hs-comment">--</span><span>
</span><span id="line-355"></span><span>      </span><span class="hs-comment">-- When called from cpDecode, OutputUnderflow is also possible.</span><span>
</span><span id="line-356"></span><span>      </span><span class="hs-comment">--</span><span>
</span><span id="line-357"></span><span>      </span><span class="hs-comment">-- Luckily if we have InvalidSequence/OutputUnderflow and we do not appear to have reached</span><span>
</span><span id="line-358"></span><span>      </span><span class="hs-comment">-- the target, what we should do is the same as normal because the fraction of ibuf that our</span><span>
</span><span id="line-359"></span><span>      </span><span class="hs-comment">-- first &quot;code&quot; coded successfully must be invalid-sequence-free, and ibuf will always</span><span>
</span><span id="line-360"></span><span>      </span><span class="hs-comment">-- have been decoded as far as the first invalid sequence in it.</span><span>
</span><span id="line-361"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Buffer to -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546656"><span class="hs-identifier hs-var">mbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Ordering
forall a. Ord a =&gt; a -&gt; a -&gt; Ordering
</span><a href="../../ghc-prim/src/GHC.Classes.html#compare"><span class="hs-operator hs-var">`compare`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546688"><span class="hs-identifier hs-var">target_to_elems</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-362"></span><span>        </span><span class="hs-comment">-- Coding n &quot;from&quot; chars from the input yields exactly as many &quot;to&quot; chars</span><span>
</span><span id="line-363"></span><span>        </span><span class="hs-comment">-- as were consumed by the recode. All is peachy:</span><span>
</span><span id="line-364"></span><span>        </span><span class="annot"><span class="annottext">Ordering
</span><a href="../../ghc-prim/src/GHC.Types.html#EQ"><span class="hs-identifier hs-var">EQ</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;bSearch = &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546654"><span class="hs-identifier hs-var">solution</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO Int -&gt; IO Int
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; m b -&gt; m b
</span><a href="GHC.Base.html#%3E%3E"><span class="hs-operator hs-var">&gt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546654"><span class="hs-identifier hs-var">solution</span></a></span><span>
</span><span id="line-365"></span><span>          </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679546654"><span class="annot"><span class="annottext">solution :: Int
</span><a href="#local-6989586621679546654"><span class="hs-identifier hs-var hs-var">solution</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546660"><span class="hs-identifier hs-var">md</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546657"><span class="hs-identifier hs-var">ibuf</span></a></span><span>
</span><span id="line-366"></span><span>        </span><span class="hs-comment">-- If we encoded fewer &quot;to&quot; characters than the target number, try again with more &quot;from&quot; characters (and vice-versa)</span><span>
</span><span id="line-367"></span><span>        </span><span class="annot"><span class="annottext">Ordering
</span><a href="../../ghc-prim/src/GHC.Types.html#LT"><span class="hs-identifier hs-var">LT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; IO Int
</span><a href="#local-6989586621679546652"><span class="hs-identifier hs-var">go'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546660"><span class="hs-identifier hs-var">md</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546659"><span class="hs-identifier hs-var">mx</span></a></span><span>
</span><span id="line-368"></span><span>        </span><span class="annot"><span class="annottext">Ordering
</span><a href="../../ghc-prim/src/GHC.Types.html#GT"><span class="hs-identifier hs-var">GT</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; IO Int
</span><a href="#local-6989586621679546652"><span class="hs-identifier hs-var">go'</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546661"><span class="hs-identifier hs-var">mn</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546660"><span class="hs-identifier hs-var">md</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-369"></span><span>    </span><span id="local-6989586621679546652"><span class="annot"><span class="annottext">go' :: Int -&gt; Int -&gt; IO Int
</span><a href="#local-6989586621679546652"><span class="hs-identifier hs-var hs-var">go'</span></a></span></span><span> </span><span id="local-6989586621679546651"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546651"><span class="hs-identifier hs-var">mn</span></a></span></span><span> </span><span id="local-6989586621679546650"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546650"><span class="hs-identifier hs-var">mx</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546651"><span class="hs-identifier hs-var">mn</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546650"><span class="hs-identifier hs-var">mx</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="#local-6989586621679546687"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546651"><span class="hs-identifier hs-var">mn</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546651"><span class="hs-identifier hs-var">mn</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546650"><span class="hs-identifier hs-var">mx</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546651"><span class="hs-identifier hs-var">mn</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Real.html#div"><span class="hs-operator hs-var">`div`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546650"><span class="hs-identifier hs-var">mx</span></a></span><span>
</span><span id="line-370"></span><span>              </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO Int
forall a. String -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO Int) -&gt; String -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;bSearch(&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679546692"><span class="hs-identifier hs-var">msg</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;): search crossed! &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">(String, String, Int, Int, Int) -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer from -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546690"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer to -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546689"><span class="hs-identifier hs-var">mbuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546688"><span class="hs-identifier hs-var">target_to_elems</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546651"><span class="hs-identifier hs-var">mn</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546650"><span class="hs-identifier hs-var">mx</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-371"></span><span>
</span><span id="line-372"></span><span class="annot"><a href="GHC.IO.Encoding.CodePage.API.html#cpRecode"><span class="hs-identifier hs-type">cpRecode</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679547213"><span class="annot"><a href="#local-6989586621679547213"><span class="hs-identifier hs-type">from</span></a></span></span><span> </span><span id="local-6989586621679547212"><span class="annot"><a href="#local-6989586621679547212"><span class="hs-identifier hs-type">to</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547213"><span class="hs-identifier hs-type">from</span></a></span><span>
</span><span id="line-373"></span><span>         </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547213"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547212"><span class="hs-identifier hs-type">to</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-374"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679547213"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-375"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-comment">-- ^ Maximum length of a complete translatable sequence in the input (e.g. 2 if the input is UTF-16, 1 if the input is a SBCS, 2 is the input is a DBCS). Must be at least 1.</span><span>
</span><span id="line-376"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-comment">-- ^ Minimum number of output elements per complete translatable sequence in the input (almost certainly 1)</span><span>
</span><span id="line-377"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-378"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#CodeBuffer"><span class="hs-identifier hs-type">CodeBuffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547213"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547212"><span class="hs-identifier hs-type">to</span></a></span><span>
</span><span id="line-379"></span><span id="cpRecode"><span class="annot"><span class="annottext">cpRecode :: forall from to.
Storable from =&gt;
(Ptr from -&gt; Int -&gt; Ptr to -&gt; Int -&gt; IO (Either Bool Int))
-&gt; (from -&gt; IO Bool)
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; Int
-&gt; CodeBuffer from to
</span><a href="GHC.IO.Encoding.CodePage.API.html#cpRecode"><span class="hs-identifier hs-var hs-var">cpRecode</span></a></span></span><span> </span><span id="local-6989586621679546641"><span class="annot"><span class="annottext">Ptr from -&gt; Int -&gt; Ptr to -&gt; Int -&gt; IO (Either Bool Int)
</span><a href="#local-6989586621679546641"><span class="hs-identifier hs-var">try'</span></a></span></span><span> </span><span id="local-6989586621679546640"><span class="annot"><span class="annottext">from -&gt; IO Bool
</span><a href="#local-6989586621679546640"><span class="hs-identifier hs-var">is_valid_prefix</span></a></span></span><span> </span><span id="local-6989586621679546639"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546639"><span class="hs-identifier hs-var">max_i_size</span></a></span></span><span> </span><span id="local-6989586621679546638"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546638"><span class="hs-identifier hs-var">min_o_size</span></a></span></span><span> </span><span id="local-6989586621679546637"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546637"><span class="hs-identifier hs-var">iscale</span></a></span></span><span> </span><span id="local-6989586621679546636"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546636"><span class="hs-identifier hs-var">oscale</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CodeBuffer from to
</span><a href="#local-6989586621679546635"><span class="hs-identifier hs-var">go</span></a></span><span>
</span><span id="line-380"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-381"></span><span>    </span><span class="annot"><a href="#local-6989586621679546635"><span class="hs-identifier hs-type">go</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#CodeBuffer"><span class="hs-identifier hs-type">CodeBuffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547213"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679547212"><span class="hs-identifier hs-type">to</span></a></span><span>
</span><span id="line-382"></span><span>    </span><span id="local-6989586621679546635"><span class="annot"><span class="annottext">go :: CodeBuffer from to
</span><a href="#local-6989586621679546635"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621679546634"><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span></span><span> </span><span id="local-6989586621679546633"><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546633"><span class="hs-identifier hs-var">obuf</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CodingProgress, Buffer from, Buffer to)
-&gt; IO (CodingProgress, Buffer from, Buffer to)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#InputUnderflow"><span class="hs-identifier hs-var">InputUnderflow</span></a></span><span class="hs-special">,</span><span>  </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546633"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-383"></span><span>                 </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Buffer to -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferAvailable"><span class="hs-identifier hs-var">bufferAvailable</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546633"><span class="hs-identifier hs-var">obuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546638"><span class="hs-identifier hs-var">min_o_size</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CodingProgress, Buffer from, Buffer to)
-&gt; IO (CodingProgress, Buffer from, Buffer to)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#OutputUnderflow"><span class="hs-identifier hs-var">OutputUnderflow</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546633"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-384"></span><span>                 </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
-&gt; (Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to))
-&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546631"><span class="hs-identifier hs-var">try</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer from -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Ord a =&gt; a -&gt; a -&gt; a
</span><a href="../../ghc-prim/src/GHC.Classes.html#min"><span class="hs-operator hs-var">`min`</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546639"><span class="hs-identifier hs-var">max_i_size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferAvailable"><span class="hs-identifier hs-var">bufferAvailable</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546633"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Real.html#div"><span class="hs-operator hs-var">`div`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546638"><span class="hs-identifier hs-var">min_o_size</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546630"><span class="hs-identifier hs-var">seek_smaller</span></a></span><span>
</span><span id="line-385"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-386"></span><span>        </span><span id="local-6989586621679546627"><span class="annot"><span class="annottext">done :: a -&gt; m (a, Buffer from, Buffer to)
</span><a href="#local-6989586621679546627"><span class="hs-identifier hs-var hs-var">done</span></a></span></span><span> </span><span id="local-6989586621679546626"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546626"><span class="hs-identifier hs-var">why</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a, Buffer from, Buffer to) -&gt; m (a, Buffer from, Buffer to)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679546626"><span class="hs-identifier hs-var">why</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546633"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-387"></span><span>
</span><span id="line-388"></span><span>        </span><span id="local-6989586621679546630"><span class="annot"><span class="annottext">seek_smaller :: Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546630"><span class="hs-identifier hs-var hs-var">seek_smaller</span></a></span></span><span> </span><span id="local-6989586621679546606"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546606"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621679546605"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546605"><span class="hs-identifier hs-var">longer_was_valid</span></a></span></span><span>
</span><span id="line-389"></span><span>          </span><span class="hs-comment">-- In this case, we can't shrink any further via any method. Calling (try 0) wouldn't be right because that will always claim InputUnderflow...</span><span>
</span><span id="line-390"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546606"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546605"><span class="hs-identifier hs-var">longer_was_valid</span></a></span><span>
</span><span id="line-391"></span><span>                      </span><span class="hs-comment">-- try m (where m &gt;= n) was valid but we overflowed the output buffer with even a single input element</span><span>
</span><span id="line-392"></span><span>                      </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">CodingProgress -&gt; IO (CodingProgress, Buffer from, Buffer to)
forall {m :: * -&gt; *} {a}.
Monad m =&gt;
a -&gt; m (a, Buffer from, Buffer to)
</span><a href="#local-6989586621679546627"><span class="hs-identifier hs-var">done</span></a></span><span> </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#OutputUnderflow"><span class="hs-identifier hs-var">OutputUnderflow</span></a></span><span>
</span><span id="line-393"></span><span>                      </span><span class="hs-comment">-- there was no initial valid sequence in the input, but it might just be a truncated buffer - we need to check</span><span>
</span><span id="line-394"></span><span>                      </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679546604"><span class="annot"><span class="annottext">from
</span><a href="#local-6989586621679546604"><span class="hs-identifier hs-var">byte</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; (Ptr from -&gt; IO from) -&gt; IO from
forall e a. Buffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withBuffer"><span class="hs-identifier hs-var">withBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr from -&gt; IO from) -&gt; IO from)
-&gt; (Ptr from -&gt; IO from) -&gt; IO from
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679546602"><span class="annot"><span class="annottext">Ptr from
</span><a href="#local-6989586621679546602"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr from -&gt; Int -&gt; IO from
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; IO a
</span><a href="Foreign.Storable.html#peekElemOff"><span class="hs-identifier hs-var">peekElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr from
</span><a href="#local-6989586621679546602"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer from -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-395"></span><span>                              </span><span id="local-6989586621679546600"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546600"><span class="hs-identifier hs-var">valid_prefix</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">from -&gt; IO Bool
</span><a href="#local-6989586621679546640"><span class="hs-identifier hs-var">is_valid_prefix</span></a></span><span> </span><span class="annot"><span class="annottext">from
</span><a href="#local-6989586621679546604"><span class="hs-identifier hs-var">byte</span></a></span><span>
</span><span id="line-396"></span><span>                              </span><span class="annot"><span class="annottext">CodingProgress -&gt; IO (CodingProgress, Buffer from, Buffer to)
forall {m :: * -&gt; *} {a}.
Monad m =&gt;
a -&gt; m (a, Buffer from, Buffer to)
</span><a href="#local-6989586621679546627"><span class="hs-identifier hs-var">done</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546600"><span class="hs-identifier hs-var">valid_prefix</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546639"><span class="hs-identifier hs-var">max_i_size</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#InputUnderflow"><span class="hs-identifier hs-var">InputUnderflow</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#InvalidSequence"><span class="hs-identifier hs-var">InvalidSequence</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-397"></span><span>          </span><span class="hs-comment">-- If we're already looking at very small buffers, try every n down to 1, to ensure we spot as long a sequence as exists while avoiding trying 0.</span><span>
</span><span id="line-398"></span><span>          </span><span class="hs-comment">-- Doing it this way ensures that we spot a single initial sequence of length &lt;= max_i_size if any such exists.</span><span>
</span><span id="line-399"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546606"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2A"><span class="hs-operator hs-var">*</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546639"><span class="hs-identifier hs-var">max_i_size</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
-&gt; (Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to))
-&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546631"><span class="hs-identifier hs-var">try</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546606"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679546598"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546598"><span class="hs-identifier hs-var">pred_n</span></a></span></span><span> </span><span id="local-6989586621679546597"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546597"><span class="hs-identifier hs-var">pred_n_was_valid</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546630"><span class="hs-identifier hs-var">seek_smaller</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546598"><span class="hs-identifier hs-var">pred_n</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546605"><span class="hs-identifier hs-var">longer_was_valid</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%7C%7C"><span class="hs-operator hs-var">||</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546597"><span class="hs-identifier hs-var">pred_n_was_valid</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-400"></span><span>          </span><span class="hs-comment">-- Otherwise, try a binary chop to try to either get the prefix before the invalid input, or shrink the output down so it fits</span><span>
</span><span id="line-401"></span><span>          </span><span class="hs-comment">-- in the output buffer. After the chop, try to consume extra input elements to try to recover as much of the sequence as possible if we</span><span>
</span><span id="line-402"></span><span>          </span><span class="hs-comment">-- end up chopping a multi-element input sequence into two parts.</span><span>
</span><span id="line-403"></span><span>          </span><span class="hs-comment">--</span><span>
</span><span id="line-404"></span><span>          </span><span class="hs-comment">-- Note that since max_i_size &gt;= 1:</span><span>
</span><span id="line-405"></span><span>          </span><span class="hs-comment">--  * (n `div` 2) &gt;= 1, so we don't try 0</span><span>
</span><span id="line-406"></span><span>          </span><span class="hs-comment">--  * ((n `div` 2) + (max_i_size - 1)) &lt; n, so we don't get into a loop where (seek_smaller n) calls post_divide (n `div` 2) calls (seek_smaller n)</span><span>
</span><span id="line-407"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679546593"><span class="annot"><span class="annottext">n' :: Int
</span><a href="#local-6989586621679546593"><span class="hs-identifier hs-var hs-var">n'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546606"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Integral a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Real.html#div"><span class="hs-operator hs-var">`div`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
-&gt; (Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to))
-&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546631"><span class="hs-identifier hs-var">try</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546593"><span class="hs-identifier hs-var">n'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
-&gt; Bool
-&gt; Int
-&gt; Bool
-&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546592"><span class="hs-identifier hs-var">post_divide</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546593"><span class="hs-identifier hs-var">n'</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546605"><span class="hs-identifier hs-var">longer_was_valid</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-408"></span><span>
</span><span id="line-409"></span><span>        </span><span id="local-6989586621679546592"><span class="annot"><span class="annottext">post_divide :: Int
-&gt; Bool
-&gt; Int
-&gt; Bool
-&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546592"><span class="hs-identifier hs-var hs-var">post_divide</span></a></span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span>  </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span>                </span><span id="local-6989586621679546591"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546591"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546630"><span class="hs-identifier hs-var">seek_smaller</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546591"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-410"></span><span>        </span><span class="annot"><a href="#local-6989586621679546592"><span class="hs-identifier hs-var">post_divide</span></a></span><span> </span><span id="local-6989586621679546590"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546590"><span class="hs-identifier hs-var">n'</span></a></span></span><span> </span><span id="local-6989586621679546589"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546589"><span class="hs-identifier hs-var">longer_was_valid</span></a></span></span><span> </span><span id="local-6989586621679546588"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546588"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546588"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546590"><span class="hs-identifier hs-var">n'</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546639"><span class="hs-identifier hs-var">max_i_size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
-&gt; (Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to))
-&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546631"><span class="hs-identifier hs-var">try</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546588"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
-&gt; Bool
-&gt; Int
-&gt; Bool
-&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546592"><span class="hs-identifier hs-var">post_divide</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546590"><span class="hs-identifier hs-var">n'</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546589"><span class="hs-identifier hs-var">longer_was_valid</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- There's still a chance..</span><span>
</span><span id="line-411"></span><span>                                                </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>               </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546630"><span class="hs-identifier hs-var">seek_smaller</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546590"><span class="hs-identifier hs-var">n'</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679546589"><span class="hs-identifier hs-var">longer_was_valid</span></a></span><span>              </span><span class="hs-comment">-- No amount of recovery could save us :(</span><span>
</span><span id="line-412"></span><span>
</span><span id="line-413"></span><span>        </span><span id="local-6989586621679546631"><span class="annot"><span class="annottext">try :: Int
-&gt; (Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to))
-&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546631"><span class="hs-identifier hs-var hs-var">try</span></a></span></span><span> </span><span id="local-6989586621679546577"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546577"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621679546576"><span class="annot"><span class="annottext">Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546576"><span class="hs-identifier hs-var">k_fail</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer from
-&gt; (Ptr from -&gt; IO (CodingProgress, Buffer from, Buffer to))
-&gt; IO (CodingProgress, Buffer from, Buffer to)
forall e a. Buffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withBuffer"><span class="hs-identifier hs-var">withBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr from -&gt; IO (CodingProgress, Buffer from, Buffer to))
 -&gt; IO (CodingProgress, Buffer from, Buffer to))
-&gt; (Ptr from -&gt; IO (CodingProgress, Buffer from, Buffer to))
-&gt; IO (CodingProgress, Buffer from, Buffer to)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679546575"><span class="annot"><span class="annottext">Ptr from
</span><a href="#local-6989586621679546575"><span class="hs-identifier hs-var">iptr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Buffer to
-&gt; (Ptr to -&gt; IO (CodingProgress, Buffer from, Buffer to))
-&gt; IO (CodingProgress, Buffer from, Buffer to)
forall e a. Buffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withBuffer"><span class="hs-identifier hs-var">withBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546633"><span class="hs-identifier hs-var">obuf</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr to -&gt; IO (CodingProgress, Buffer from, Buffer to))
 -&gt; IO (CodingProgress, Buffer from, Buffer to))
-&gt; (Ptr to -&gt; IO (CodingProgress, Buffer from, Buffer to))
-&gt; IO (CodingProgress, Buffer from, Buffer to)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679546574"><span class="annot"><span class="annottext">Ptr to
</span><a href="#local-6989586621679546574"><span class="hs-identifier hs-var">optr</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-414"></span><span>          </span><span id="local-6989586621679546573"><span class="annot"><span class="annottext">Either Bool Int
</span><a href="#local-6989586621679546573"><span class="hs-identifier hs-var">ei_err_wrote</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr from -&gt; Int -&gt; Ptr to -&gt; Int -&gt; IO (Either Bool Int)
</span><a href="#local-6989586621679546641"><span class="hs-identifier hs-var">try'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr from
</span><a href="#local-6989586621679546575"><span class="hs-identifier hs-var">iptr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr from -&gt; Int -&gt; Ptr from
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer from -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Bits a =&gt; a -&gt; Int -&gt; a
</span><a href="Data.Bits.html#shiftL"><span class="hs-operator hs-var">`shiftL`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546637"><span class="hs-identifier hs-var">iscale</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546577"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-415"></span><span>                               </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr to
</span><a href="#local-6989586621679546574"><span class="hs-identifier hs-var">optr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr to -&gt; Int -&gt; Ptr to
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer to -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546633"><span class="hs-identifier hs-var">obuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Bits a =&gt; a -&gt; Int -&gt; a
</span><a href="Data.Bits.html#shiftL"><span class="hs-operator hs-var">`shiftL`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546636"><span class="hs-identifier hs-var">oscale</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer to -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferAvailable"><span class="hs-identifier hs-var">bufferAvailable</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546633"><span class="hs-identifier hs-var">obuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-416"></span><span>          </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Encoding.CodePage.API.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;try &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546577"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; = &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Either Bool Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Either Bool Int
</span><a href="#local-6989586621679546573"><span class="hs-identifier hs-var">ei_err_wrote</span></a></span><span>
</span><span id="line-417"></span><span>          </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Either Bool Int
</span><a href="#local-6989586621679546573"><span class="hs-identifier hs-var">ei_err_wrote</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-418"></span><span>            </span><span class="hs-comment">-- ERROR_INSUFFICIENT_BUFFER: A supplied buffer size was not large enough, or it was incorrectly set to NULL.</span><span>
</span><span id="line-419"></span><span>            </span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546576"><span class="hs-identifier hs-var">k_fail</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546577"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-420"></span><span>            </span><span class="hs-comment">-- ERROR_NO_UNICODE_TRANSLATION: Invalid Unicode was found in a string.</span><span>
</span><span id="line-421"></span><span>            </span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Bool -&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679546576"><span class="hs-identifier hs-var">k_fail</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546577"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-422"></span><span>            </span><span class="hs-comment">-- Must have interpreted all given bytes successfully</span><span>
</span><span id="line-423"></span><span>            </span><span class="hs-comment">-- We need to iterate until we have consumed the complete contents of the buffer</span><span>
</span><span id="line-424"></span><span>            </span><span class="annot"><a href="Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span id="local-6989586621679546570"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546570"><span class="hs-identifier hs-var">wrote_elts</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CodeBuffer from to
</span><a href="#local-6989586621679546635"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Buffer from -&gt; Buffer from
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferRemove"><span class="hs-identifier hs-var">bufferRemove</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546577"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679546634"><span class="hs-identifier hs-var">ibuf</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546633"><span class="hs-identifier hs-var">obuf</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer to -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679546633"><span class="hs-identifier hs-var">obuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679546570"><span class="hs-identifier hs-var">wrote_elts</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-425"></span></pre></body></html>